Skip to content

Commit 1b5d9d0

Browse files
committed
Add CP297 code page (France).
1 parent a21e90b commit 1b5d9d0

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ The output looks like this:
16321632
| .option("ebcdic_code_page", "cp280") | EBCDIC 280 | Italy. |
16331633
| .option("ebcdic_code_page", "cp284") | EBCDIC 284 | Spain and Latin America. |
16341634
| .option("ebcdic_code_page", "cp285") | EBCDIC 285 | United Kingdom. |
1635+
| .option("ebcdic_code_page", "cp297") | EBCDIC 297 | France. |
16351636
| .option("ebcdic_code_page", "cp300") | EBCDIC 300 | Double-byte code page with Japanese and Latin characters. |
16361637
| .option("ebcdic_code_page", "cp500") | EBCDIC 500 | Belgium, Canada, Switzerland, International. |
16371638
| .option("ebcdic_code_page", "cp838") | EBCDIC 838 | Double-byte code page with Thai and Latin characters. |

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
@@ -52,6 +52,7 @@ object CodePage extends Logging {
5252
case "cp280" => new CodePage280
5353
case "cp284" => new CodePage284
5454
case "cp285" => new CodePage285
55+
case "cp297" => new CodePage297
5556
case "cp300" => new CodePage300
5657
case "cp500" => new CodePage500
5758
case "cp838" => new CodePage838
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 285 is used to represent characters of France.
21+
*/
22+
class CodePage297 extends SingleByteCodePage(CodePage297.ebcdicToAsciiMapping) {
23+
override def codePageShortName: String = "cp297"
24+
}
25+
26+
object CodePage297 {
27+
val ebcdicToAsciiMapping: Array[Char] = {
28+
import EbcdicNonPrintable._
29+
30+
/* This is the EBCDIC Code Page 297 to ASCII conversion table
31+
from https://en.wikibooks.org/wiki/Character_Encodings/Code_Tables/EBCDIC/EBCDIC_297 */
32+
val ebcdic2ascii: Array[Char] = {
33+
// Non-printable characters map used: http://www.pacsys.com/asciitab.htm
34+
Array[Char](
35+
c00, c01, c02, c03, spc, c09, spc, del, spc, spc, spc, c0b, c0c, ccr, c0e, c0f, // 0 - 15
36+
c10, c11, c12, c13, spc, nel, c08, spc, c18, c19, spc, spc, c1c, c1d, c1e, c1f, // 16 - 31
37+
spc, spc, spc, spc, spc, clf, c17, c1b, spc, spc, spc, spc, spc, c05, c06, c07, // 32 - 47
38+
spc, spc, c16, spc, spc, spc, spc, c04, spc, spc, spc, spc, c14, c15, spc, c1a, // 48 - 63
39+
' ', rsp, 'â', 'ä', '@', 'á', 'ã', 'å', bsh, 'ñ', '°', '.', '<', '(', '+', '!', // 64 - 79
40+
'&', '{', 'ê', 'ë', '}', 'í', 'î', 'ï', 'ì', 'ß', '§', '$', '*', ')', ';', '^', // 80 - 95
41+
'-', '/', 'Â', 'Ä', 'À', 'Á', 'Ã', 'Å', 'Ç', 'Ñ', 'ù', ',', '%', '_', '>', '?', // 96 - 111
42+
'ø', 'É', 'Ê', 'Ë', 'È', 'Í', 'Î', 'Ï', 'Ì', 'µ', ':', '£', 'à', qts, '=', qtd, // 112 - 127
43+
'Ø', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', '«', '»', 'ð', 'ý', 'þ', '±', // 128 - 143
44+
'[', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 'ª', 'º', 'æ', '¸', 'Æ', '¤', // 144 - 159
45+
'`', '¨', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '¡', '¿', 'Ð', 'Ý', 'Þ', '®', // 160 - 175
46+
'¢', '#', '¥', '·', '©', ']', '¶', '¼', '½', '¾', '¬', '|', '¯', '~', '´', '×', // 176 - 191
47+
'é', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', shy, 'ô', 'ö', 'ò', 'ó', 'õ', // 192 - 207
48+
'è', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', '¹', 'û', 'ü', '¦', 'ú', 'ÿ', // 208 - 223
49+
'ç', '÷', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '²', 'Ô', 'Ö', 'Ò', 'Ó', 'Õ', // 224 - 239
50+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '³', 'Û', 'Ü', 'Ù', 'Ú', spc) // 240 - 255
51+
}
52+
ebcdic2ascii
53+
}
54+
}

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
@@ -196,6 +196,17 @@ class StringDecodersSpec extends AnyWordSpec {
196196
assert(actual == expected)
197197
}
198198

199+
"decode a CP297 string special characters" in {
200+
val expected = " °$¨¢#¬¯ä£!üÜ^]ù§ß¢°Öéèæö¨åàÆØÅÄɤ "
201+
val bytes = Array(0x40, 0x4A, 0x5B, 0xA1, 0xB0, 0xB1, 0xBA, 0xBC, 0x43, 0x7B, 0x4F, 0xDC, 0xFC, 0x5F, 0xB5, 0x6A, 0x5A, 0x59,
202+
0xB0, 0x4A, 0xEC, 0xC0, 0xD0, 0x9C, 0xCC, 0xA1, 0x47, 0x7C, 0x9E, 0x80, 0x67, 0x63,
203+
0x71, 0x9F, 0x40).map(_.toByte)
204+
205+
val actual = decodeEbcdicString(bytes, KeepAll, new CodePage297, improvedNullDetection = false)
206+
207+
assert(actual == expected)
208+
}
209+
199210
"decode a CP500 string special characters" in {
200211
val expected = "âäàáãåçñ[.<(+!&éêëèíîïìß]$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿ÐÝÞ®¢£¥·©§¶¼½¾¬|¯¨´×{ABCDEFGHI\u00ADôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙÚ"
201212
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
@@ -77,6 +77,11 @@ class CodePageSingleByteSpec extends AnyFunSuite {
7777
assert(codePage.codePageShortName == "cp285")
7878
}
7979

80+
test("Ensure codepage 'cp297' gives the associated CodePage") {
81+
val codePage = CodePage.getCodePageByName("cp297")
82+
assert(codePage.codePageShortName == "cp297")
83+
}
84+
8085
test("Ensure codepage 'cp300' gives the associated CodePage") {
8186
val codePage = CodePage.getCodePageByName("cp300")
8287
assert(codePage.codePageShortName == "cp300")

0 commit comments

Comments
 (0)