Skip to content

Commit 57be16a

Browse files
committed
#792 Fix PR suggestions. Thanks @coderabbitai!
1 parent a1bc838 commit 57be16a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/codepage/SingleByteCodePage.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ abstract class SingleByteCodePage(ebcdicToAsciiMapping: Array[Char], asciiToEbcd
5454
final override def convert(string: String, length: Int): Array[Byte] = {
5555
require(length >= 0, s"Field length cannot be negative, got $length")
5656

57-
var i = 0
5857
val buf = new Array[Byte](length)
5958

6059
// PIC X fields are space-filled on mainframe. Use EBCDIC space 0x40.
@@ -63,14 +62,15 @@ abstract class SingleByteCodePage(ebcdicToAsciiMapping: Array[Char], asciiToEbcd
6362
val conversionTable = asciiToEbcdicMapping
6463
val maxChar = conversionTable.length - 1
6564

66-
while (i < string.length && i < length) {
67-
val unicodeCodePoint: Int = string.codePointAt(i)
68-
69-
buf(i) = if (unicodeCodePoint > maxChar)
70-
0x40.toByte
71-
else
72-
conversionTable(unicodeCodePoint)
73-
i = i + 1
65+
var inPos = 0
66+
var outPos = 0
67+
while (inPos < string.length && outPos < length) {
68+
val unicodeCodePoint = string.codePointAt(inPos)
69+
if (unicodeCodePoint <= maxChar) {
70+
buf(outPos) = conversionTable(unicodeCodePoint)
71+
}
72+
outPos += 1
73+
inPos += Character.charCount(unicodeCodePoint)
7474
}
7575
buf
7676
}

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/parse/SyntaxErrorsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SyntaxErrorsSpec extends AnyFunSuite {
7777
assert(syntaxErrorException.lineNumber == 4)
7878
assert(syntaxErrorException.posOpt.isEmpty)
7979
assert(syntaxErrorException.fieldOpt.contains("SUB_FLD2"))
80-
assert(syntaxErrorException.msg.contains("The field SUB_FLD2 redefines SUB_FLD1, which is not part if the redefined fields block"))
80+
assert(syntaxErrorException.msg.contains("The field SUB_FLD2 redefines SUB_FLD1, which is not part of the redefined fields block"))
8181
}
8282

8383
test("Test too big decimal precision") {

0 commit comments

Comments
 (0)