Skip to content

Commit 20e93ad

Browse files
committed
#730 Add code page CP1146.
1 parent f9be3c7 commit 20e93ad

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object CodePage extends Logging {
6363
case "cp1140" => new CodePage1140
6464
case "cp1141" => new CodePage1141
6565
case "cp1145" => new CodePage1145
66+
case "cp1146" => new CodePage1146
6667
case "cp1148" => new CodePage1148
6768
case "cp1364" => new CodePage1364
6869
case "cp1388" => new CodePage1388

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
package za.co.absa.cobrix.cobol.parser.encoding.codepage
1818

1919
/**
20-
* EBCDIC code page 284 is used to represent characters of Spain and Latin America.
20+
* EBCDIC code page 1145 is used to represent characters of Spain and Latin America
21+
* with € at the position of the international currency symbol ¤.
2122
*/
2223
class CodePage1145 extends SingleByteCodePage(CodePage1145.ebcdicToAsciiMapping) {
2324
override def codePageShortName: String = "cp1145"
@@ -27,7 +28,7 @@ object CodePage1145 {
2728
val ebcdicToAsciiMapping: Array[Char] = {
2829
import EbcdicNonPrintable._
2930

30-
/* This is the EBCDIC Code Page 1145 which is the euro currency update of code page CCSID 284
31+
/* This is the EBCDIC Code Page 1145 which is the euro currency update of code page CCSID 284
3132
from https://en.wikibooks.org/wiki/Character_Encodings/Code_Tables/EBCDIC/EBCDIC_284 */
3233
val ebcdic2ascii: Array[Char] = {
3334
// Non-printable characters map used: http://www.pacsys.com/asciitab.htm
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2018 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package za.co.absa.cobrix.cobol.parser.encoding.codepage
18+
19+
/**
20+
* EBCDIC code page 1146 is used to represent characters of the United Kingdom
21+
* with € at the position of the international currency symbol ¤.
22+
*/
23+
class CodePage1146 extends SingleByteCodePage(CodePage1146.ebcdicToAsciiMapping) {
24+
override def codePageShortName: String = "cp1146"
25+
}
26+
27+
object CodePage1146 {
28+
val ebcdicToAsciiMapping: Array[Char] = {
29+
import EbcdicNonPrintable._
30+
31+
/* This is the EBCDIC Code Page 1146 which is the euro currency update of code page CCSID 285
32+
from https://en.wikibooks.org/wiki/Character_Encodings/Code_Tables/EBCDIC/EBCDIC_285 */
33+
val ebcdic2ascii: Array[Char] = {
34+
// Non-printable characters map used: http://www.pacsys.com/asciitab.htm
35+
Array[Char](
36+
c00, c01, c02, c03, spc, c09, spc, del, spc, spc, spc, c0b, c0c, ccr, c0e, c0f, // 0 - 15
37+
c10, c11, c12, c13, spc, nel, c08, spc, c18, c19, spc, spc, c1c, c1d, c1e, c1f, // 16 - 31
38+
spc, spc, spc, spc, spc, clf, c17, c1b, spc, spc, spc, spc, spc, c05, c06, c07, // 32 - 47
39+
spc, spc, c16, spc, spc, spc, spc, c04, spc, spc, spc, spc, c14, c15, spc, c1a, // 48 - 63
40+
' ', rsp, 'â', 'ä', 'à', 'á', 'ã', 'å', 'ç', 'ñ', '$', '.', '<', '(', '+', '|', // 64 - 79
41+
'&', 'é', 'ê', 'ë', 'è', 'í', 'î', 'ï', 'ì', 'ß', '!', '£', '*', ')', ';', '¬', // 80 - 95
42+
'-', '/', 'Â', 'Ä', 'À', 'Á', 'Ã', 'Å', 'Ç', 'Ñ', '¦', ',', '%', '_', '>', '?', // 96 - 111
43+
'ø', 'É', 'Ê', 'Ë', 'È', 'Í', 'Î', 'Ï', 'Ì', '`', ':', '#', '@', qts, '=', qtd, // 112 - 127
44+
'Ø', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '«', '»', 'ð', 'ý', 'þ', '±', // 128 - 143
45+
'°', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 'ª', 'º', 'æ', '¸', 'Æ', '€', // 144 - 159
46+
'µ', '¯', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '¡', '¿', 'Ð', 'Ý', 'Þ', '®', // 160 - 175
47+
'¢', '[', '¥', '·', '©', '§', '¶', '¼', '½', '¾', '^', ']', '~', '¨', '´', '×', // 176 - 191
48+
'{', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', shy, 'ô', 'ö', 'ò', 'ó', 'õ', // 192 - 207
49+
'}', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', '¹', 'û', 'ü', 'ù', 'ú', 'ÿ', // 208 - 223
50+
bsh, '÷', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '²', 'Ô', 'Ö', 'Ò', 'Ó', 'Õ', // 224 - 239
51+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '³', 'Û', 'Ü', 'Ù', 'Ú', spc) // 240 - 255
52+
}
53+
ebcdic2ascii
54+
}
55+
}

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/decoders/StringDecodersSpec.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ class StringDecodersSpec extends AnyWordSpec {
285285
assert(actual == expected)
286286
}
287287

288+
"decode a CP1146 string special characters" in {
289+
val expected = " $£¯¢[^~ä#|üܬ§¦!ߢ$Ö{}æö¯å@ÆØÅÄÉ€ "
290+
val bytes = Array(0x40, 0x4A, 0x5B, 0xA1, 0xB0, 0xB1, 0xBA, 0xBC, 0x43, 0x7B, 0x4F, 0xDC, 0xFC, 0x5F, 0xB5, 0x6A, 0x5A, 0x59,
291+
0xB0, 0x4A, 0xEC, 0xC0, 0xD0, 0x9C, 0xCC, 0xA1, 0x47, 0x7C, 0x9E, 0x80, 0x67, 0x63,
292+
0x71, 0x9F, 0x40).map(_.toByte)
293+
294+
val actual = decodeEbcdicString(bytes, KeepAll, new CodePage1146, improvedNullDetection = false)
295+
296+
assert(actual == expected)
297+
}
298+
288299
"decode a CP1148 string special characters" in {
289300
val expected = "âäàáãåçñ[.<(+!&éêëèíîïìß]$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ€µ~stuvwxyz¡¿ÐÝÞ®¢£¥·©§¶¼½¾¬|¯¨´×{ABCDEFGHI\u00ADôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙÚ"
290301
val bytes = Array(

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/encoding/codepage/CodePageSingleByteSpec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class CodePageSingleByteSpec extends AnyFunSuite {
132132
assert(codePage.codePageShortName == "cp1145")
133133
}
134134

135+
test("Ensure codepage 'cp1146' gives the associated CodePage") {
136+
val codePage = CodePage.getCodePageByName("cp1146")
137+
assert(codePage.codePageShortName == "cp1146")
138+
}
139+
135140
test("Ensure codepage 'cp1148' gives the associated CodePage") {
136141
val codePage = CodePage.getCodePageByName("cp1148")
137142
assert(codePage.codePageShortName == "cp1148")

0 commit comments

Comments
 (0)