Skip to content

Commit 8be3e49

Browse files
committed
#730 Add CP274 (Belgium).
1 parent cf311c3 commit 8be3e49

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
@@ -1625,6 +1625,7 @@ The output looks like this:
16251625
| .option("ebcdic_code_page", "common") | Common | (Default) Only characters common across EBCDIC code pages are decoded. |
16261626
| .option("ebcdic_code_page", "cp037") | EBCDIC 037 | Australia, Brazil, Canada, New Zealand, Portugal, South Africa, USA. |
16271627
| .option("ebcdic_code_page", "cp273") | EBCDIC 273 | Germany, Austria. |
1628+
| .option("ebcdic_code_page", "cp274") | EBCDIC 274 | Belgium. |
16281629
| .option("ebcdic_code_page", "cp275") | EBCDIC 275 | Brazil. |
16291630
| .option("ebcdic_code_page", "cp277") | EBCDIC 277 | Denmark and Norway. |
16301631
| .option("ebcdic_code_page", "cp278") | EBCDIC 278 | Finland and Sweden. |

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
@@ -46,6 +46,7 @@ object CodePage extends Logging {
4646
case "cp037_extended" => new CodePage037Ext
4747
case "cp00300" => new CodePage300 // This is the same as cp300
4848
case "cp273" => new CodePage273
49+
case "cp274" => new CodePage274
4950
case "cp275" => new CodePage275
5051
case "cp277" => new CodePage277
5152
case "cp278" => new CodePage278
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 274. Belgium.
21+
*/
22+
class CodePage274 extends SingleByteCodePage(CodePage274.ebcdicToAsciiMapping) {
23+
override def codePageShortName: String = "cp274"
24+
}
25+
26+
object CodePage274 {
27+
val ebcdicToAsciiMapping: Array[Char] = {
28+
import EbcdicNonPrintable._
29+
30+
/* This is the EBCDIC Code Page 274 to ASCII conversion table
31+
from https://en.wikibooks.org/wiki/Character_Encodings/Code_Tables/EBCDIC/EBCDIC_274 */
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
@@ -105,6 +105,17 @@ class StringDecodersSpec extends AnyWordSpec {
105105
assert(actual == expected)
106106
}
107107

108+
"decode a CP274 string special characters" in {
109+
val expected = " æÄ!üÜ^Æö]ߢ§Øäèéø¨åÖ#àÅ[ç¤Ç "
110+
val bytes = Array(0x40, 0x9C, 0x63, 0x4F, 0xDC, 0xFC, 0x5F, 0x9E, 0xCC, 0x5A, 0x59,
111+
0xB0, 0xB5, 0x80, 0x43, 0xD0, 0xC0, 0x70, 0xA1, 0x47, 0xEC, 0x7B, 0x7C, 0x67, 0x4A,
112+
0xE0, 0x9F, 0x68, 0x40).map(_.toByte)
113+
114+
val actual = decodeEbcdicString(bytes, KeepAll, new CodePage274, improvedNullDetection = false)
115+
116+
assert(actual == expected)
117+
}
118+
108119
"decode a CP275 string special characters" in {
109120
val expected = " æÄ!üÜ^Æö$ߢ§Øäéõø~åÖÕÃÅÉ\\¤] "
110121
val bytes = Array(0x40, 0x9C, 0x63, 0x4F, 0xDC, 0xFC, 0x5F, 0x9E, 0xCC, 0x5A, 0x59,

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
@@ -47,6 +47,11 @@ class CodePageSingleByteSpec extends AnyFunSuite {
4747
assert(codePage.codePageShortName == "cp273")
4848
}
4949

50+
test("Ensure codepage 'cp274' gives the associated CodePage") {
51+
val codePage = CodePage.getCodePageByName("cp274")
52+
assert(codePage.codePageShortName == "cp274")
53+
}
54+
5055
test("Ensure codepage 'cp275' gives the associated CodePage") {
5156
val codePage = CodePage.getCodePageByName("cp275")
5257
assert(codePage.codePageShortName == "cp275")

0 commit comments

Comments
 (0)