Skip to content

Commit 91d7e45

Browse files
committed
Fix a typo a parameter name and add more tests for teh relaxed sign overpunch mode.
1 parent db7be2a commit 91d7e45

File tree

4 files changed

+330
-280
lines changed

4 files changed

+330
-280
lines changed

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/decoders/StringDecoders.scala

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ object StringDecoders {
162162
* @param bytes A byte array that represents the binary data
163163
* @param isUnsigned If true, negative numbers will be considered invalid and return null
164164
* @param allowSignOverpunch If true, sign overpunching is allowed
165-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
165+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
166166
* @param improvedNullDetection If true, return null if all bytes are zero
167167
* @return A string representation of the binary data
168168
*/
169-
final def decodeEbcdicNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): String = {
169+
final def decodeEbcdicNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): String = {
170170
if (improvedNullDetection && isNumberNull(bytes))
171171
return null
172172

@@ -178,7 +178,7 @@ object StringDecoders {
178178
while (i < bytes.length) {
179179
val b = bytes(i) & 0xFF
180180
var ch = ' '
181-
if (sign != ' ' && !relaxedOvepunch) {
181+
if (sign != ' ' && !relaxedOverpunch) {
182182
// Handle characters after a sign character is encountered
183183
if (b >= 0xF0 && b <= 0xF9) {
184184
ch = (b - 0xF0 + 0x30).toChar // unsigned
@@ -194,11 +194,11 @@ object StringDecoders {
194194
} else if (b >= 0xF0 && b <= 0xF9) {
195195
ch = (b - 0xF0 + 0x30).toChar // unsigned
196196
}
197-
else if ((allowSignOverpunch || relaxedOvepunch) && b >= 0xC0 && b <= 0xC9) {
197+
else if ((allowSignOverpunch || relaxedOverpunch) && b >= 0xC0 && b <= 0xC9) {
198198
ch = (b - 0xC0 + 0x30).toChar // positive sign punched
199199
sign = '+'
200200
}
201-
else if ((allowSignOverpunch || relaxedOvepunch) && b >= 0xD0 && b <= 0xD9) {
201+
else if ((allowSignOverpunch || relaxedOverpunch) && b >= 0xD0 && b <= 0xD9) {
202202
ch = (b - 0xD0 + 0x30).toChar // negative sign punched
203203
sign = '-'
204204
}
@@ -235,11 +235,11 @@ object StringDecoders {
235235
* @param bytes A byte array that represents the binary data
236236
* @param isUnsigned If true, negative numbers will be considered invalid and return null
237237
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
238-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
238+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
239239
* @param improvedNullDetection If true, return null if all bytes are zero
240240
* @return A string representation of the binary data
241241
*/
242-
final def decodeAsciiNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): String = {
242+
final def decodeAsciiNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): String = {
243243
val allowedDigitChars = " 0123456789"
244244
val punchedSignChars = "{ABCDEFGHI}JKLMNOPQR"
245245

@@ -271,7 +271,7 @@ object StringDecoders {
271271
} else if (char == '.' || char == ',') {
272272
buf.append('.')
273273
} else {
274-
if (relaxedOvepunch) {
274+
if (relaxedOverpunch) {
275275
if (punchedSignChars.contains(char)) {
276276
decodeOverpunchedSign(char)
277277
} else {
@@ -303,13 +303,13 @@ object StringDecoders {
303303
* @param bytes A byte array that represents the binary data
304304
* @param isUnsigned If true, negative numbers will be considered invalid and return null
305305
* @param allowSignOverpunch If true, sign overpunching is allowed
306-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
306+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
307307
* @param improvedNullDetection If true, return null if all bytes are zero
308308
* @return A boxed integer
309309
*/
310-
final def decodeEbcdicInt(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): Integer = {
310+
final def decodeEbcdicInt(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): Integer = {
311311
try {
312-
decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection).toInt
312+
decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection).toInt
313313
} catch {
314314
case NonFatal(_) => null
315315
}
@@ -321,13 +321,13 @@ object StringDecoders {
321321
* @param bytes A byte array that represents the binary data
322322
* @param isUnsigned If true, negative numbers will be considered invalid and return null
323323
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
324-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
324+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
325325
* @param improvedNullDetection If true, return null if all bytes are zero
326326
* @return A boxed integer
327327
*/
328-
final def decodeAsciiInt(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): Integer = {
328+
final def decodeAsciiInt(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): Integer = {
329329
try {
330-
decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection).toInt
330+
decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection).toInt
331331
} catch {
332332
case NonFatal(_) => null
333333
}
@@ -339,13 +339,13 @@ object StringDecoders {
339339
* @param bytes A byte array that represents the binary data
340340
* @param isUnsigned If true, negative numbers will be considered invalid and return null
341341
* @param allowSignOverpunch If true, sign overpunching is allowed
342-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
342+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
343343
* @param improvedNullDetection If true, return null if all bytes are zero
344344
* @return A boxed long
345345
*/
346-
final def decodeEbcdicLong(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
346+
final def decodeEbcdicLong(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
347347
try {
348-
decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection).toLong
348+
decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection).toLong
349349
} catch {
350350
case NonFatal(_) => null
351351
}
@@ -357,13 +357,13 @@ object StringDecoders {
357357
* @param bytes A byte array that represents the binary data
358358
* @param isUnsigned If true, negative numbers will be considered invalid and return null
359359
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
360-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
360+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
361361
* @param improvedNullDetection If true, return null if all bytes are zero
362362
* @return A boxed long
363363
*/
364-
final def decodeAsciiLong(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
364+
final def decodeAsciiLong(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): java.lang.Long = {
365365
try {
366-
decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection).toLong
366+
decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection).toLong
367367
} catch {
368368
case NonFatal(_) => null
369369
}
@@ -375,15 +375,15 @@ object StringDecoders {
375375
* @param bytes A byte array that represents the binary data
376376
* @param isUnsigned If true, negative numbers will be considered invalid and return null
377377
* @param allowSignOverpunch If true, sign overpunching is allowed
378-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
378+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
379379
* @param improvedNullDetection If true, return null if all bytes are zero
380380
* @param scale A decimal scale in case decimal number with implicit decimal point is expected
381381
* @param scaleFactor Additional zeros to be added before of after the decimal point
382382
* @return A big decimal containing a big integral number
383383
*/
384-
final def decodeEbcdicBigNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
384+
final def decodeEbcdicBigNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
385385
try {
386-
BigDecimal(BinaryUtils.addDecimalPoint(decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection), scale, scaleFactor))
386+
BigDecimal(BinaryUtils.addDecimalPoint(decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection), scale, scaleFactor))
387387
} catch {
388388
case NonFatal(_) => null
389389
}
@@ -395,15 +395,15 @@ object StringDecoders {
395395
* @param bytes A byte array that represents the binary data
396396
* @param isUnsigned If true, negative numbers will be considered invalid and return null
397397
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
398-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
398+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
399399
* @param improvedNullDetection If true, return null if all bytes are zero
400400
* @param scale A decimal scale in case decimal number with implicit decimal point is expected
401401
* @param scaleFactor Additional zeros to be added before of after the decimal point
402402
* @return A big decimal containing a big integral number
403403
*/
404-
final def decodeAsciiBigNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
404+
final def decodeAsciiBigNumber(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean, scale: Int = 0, scaleFactor: Int = 0): BigDecimal = {
405405
try {
406-
BigDecimal(BinaryUtils.addDecimalPoint(decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection), scale, scaleFactor))
406+
BigDecimal(BinaryUtils.addDecimalPoint(decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection), scale, scaleFactor))
407407
} catch {
408408
case NonFatal(_) => null
409409
}
@@ -416,13 +416,13 @@ object StringDecoders {
416416
* @param bytes A byte array that represents the binary data
417417
* @param isUnsigned If true, negative numbers will be considered invalid and return null
418418
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
419-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
419+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
420420
* @param improvedNullDetection If true, return null if all bytes are zero
421421
* @return A big decimal containing a big integral number
422422
*/
423-
final def decodeEbcdicBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): BigDecimal = {
423+
final def decodeEbcdicBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): BigDecimal = {
424424
try {
425-
BigDecimal(decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection))
425+
BigDecimal(decodeEbcdicNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection))
426426
} catch {
427427
case NonFatal(_) => null
428428
}
@@ -435,13 +435,13 @@ object StringDecoders {
435435
* @param bytes A byte array that represents the binary data
436436
* @param isUnsigned If true, negative numbers will be considered invalid and return null
437437
* @param allowSignOverpunch If true, sign overpunching is allowed in first or last position
438-
* @param relaxedOvepunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
438+
* @param relaxedOverpunch If true, multiple sign overpunching characters are allowed. The last one is going to be effective
439439
* @param improvedNullDetection If true, return null if all bytes are zero
440440
* @return A big decimal containing a big integral number
441441
*/
442-
final def decodeAsciiBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOvepunch: Boolean, improvedNullDetection: Boolean): BigDecimal = {
442+
final def decodeAsciiBigDecimal(bytes: Array[Byte], isUnsigned: Boolean, allowSignOverpunch: Boolean, relaxedOverpunch: Boolean, improvedNullDetection: Boolean): BigDecimal = {
443443
try {
444-
BigDecimal(decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOvepunch, improvedNullDetection))
444+
BigDecimal(decodeAsciiNumber(bytes, isUnsigned, allowSignOverpunch, relaxedOverpunch, improvedNullDetection))
445445
} catch {
446446
case NonFatal(_) => null
447447
}

0 commit comments

Comments
 (0)