Skip to content

Commit eb25686

Browse files
Fix bugs related to UTF-8 (#604)
1 parent 08ea0bd commit eb25686

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

cobj/codegen.c

+2
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,7 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) {
24522452
joutput_data(x);
24532453
joutput(".fillBytes(%d, %d);\n", buffchar, f->size);
24542454
} else {
2455+
#if !I18N_UTF8
24552456
if (f->size >= 8) {
24562457
buffchar = *(buff + f->size - 1);
24572458
int n = 0;
@@ -2471,6 +2472,7 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) {
24712472
return;
24722473
}
24732474
}
2475+
#endif
24742476
joutput_data(x);
24752477
#if I18N_UTF8
24762478
joutput(".setByByteArrayAndPaddingSpaces (");

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/termio/CobolTerminal.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ private static void displayAlnum(AbstractCobolField f, PrintStream stream) {
7575
CobolDataStorage storage = f.getDataStorage();
7676
if (CobolUtil.terminalEncoding == CobolEncoding.UTF8) {
7777
byte[] utf8Bytes =
78-
new String(
79-
storage.getByteArrayRef(0, f.getSize()),
80-
AbstractCobolField.charSetSJIS)
78+
new String(storage.getByteArray(0, f.getSize()), AbstractCobolField.charSetSJIS)
8179
.getBytes(StandardCharsets.UTF_8);
8280
stream.write(utf8Bytes, 0, utf8Bytes.length);
8381
} else {

tests/cobol_utf8.src/pic-x.at

+53
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,59 @@ AT_CHECK([diff out1.txt out2.txt])
561561

562562
AT_CLEANUP
563563

564+
AT_SETUP([Group item COB_TERMINAL_ENCODING])
565+
566+
AT_DATA([prog.cbl], [
567+
IDENTIFICATION DIVISION.
568+
PROGRAM-ID. prog.
569+
DATA DIVISION.
570+
WORKING-STORAGE SECTION.
571+
01 WK-AREA.
572+
03 WK-CD PIC X(04).
573+
03 WK-NAME PIC X(20).
574+
03 WK-DPT-CD PIC X(02).
575+
03 WK-ENT-DATE PIC 9(08).
576+
03 WK-RETURN PIC 9(01).
577+
PROCEDURE DIVISION.
578+
MAIN.
579+
MOVE "0012千葉 二郎 02199904010" TO WK-AREA.
580+
DISPLAY "従業員番号: " WK-CD.
581+
DISPLAY "名前   : " WK-NAME.
582+
DISPLAY "部署コード: " WK-DPT-CD.
583+
DISPLAY "入社日  : " WK-ENT-DATE.
584+
STOP RUN.
585+
])
586+
587+
AT_CHECK([cobj prog.cbl])
588+
AT_CHECK([COB_TERMINAL_ENCODING=UTF-8 java prog], [0],
589+
[従業員番号: 0012
590+
名前   : 千葉 二郎 @&t@
591+
部署コード: 02
592+
入社日  : 19990401
593+
])
594+
595+
AT_CLEANUP
596+
597+
AT_SETUP([Initializing Group items])
598+
599+
AT_DATA([prog.cbl], [
600+
IDENTIFICATION DIVISION.
601+
PROGRAM-ID. prog.
602+
DATA DIVISION.
603+
WORKING-STORAGE SECTION.
604+
01 F0 PIC X(17) VALUE "千葉 二郎".
605+
PROCEDURE DIVISION.
606+
DISPLAY F0.
607+
STOP RUN.
608+
])
609+
610+
AT_CHECK([cobj prog.cbl])
611+
AT_CHECK([COB_TERMINAL_ENCODING=UTF-8 java prog], [0],
612+
[千葉 二郎 @&t@
613+
])
614+
615+
AT_CLEANUP
616+
564617
#AT_SETUP([Readable string literals])
565618
#export LC_ALL=''
566619
## Older compilers converts string literals "日本語" in COBOL source code

0 commit comments

Comments
 (0)