File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
libcobj/src/jp/osscons/opensourcecobol/libcobj/data Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -420,48 +420,56 @@ static void joutput_indent(const char *str) {
420
420
static void joutput_string (const unsigned char * s , int size ) {
421
421
int i ;
422
422
int c ;
423
+ int output_multibyte = 0 ;
423
424
int printable = 1 ;
424
425
425
426
for (i = 0 ; i < size ;) {
426
427
c = s [i ];
427
- if ((0x00 <= c && c <= 0x1F ) || (c == 0x7F ) || (c == 0x80 ) || (0xf0 <= c )) {
428
- printable = 0 ;
429
- break ;
430
- } else if (i < size - 1 &&
431
- ((0x81 <= c && c <= 0x9f ) || (0xE0 <= c && c <= 0xEF ))) {
428
+ if (0x20 <= c && c <= 0x7e ) {
429
+ i += 1 ;
430
+ } else if ((0x81 <= c && c <= 0x9f ) || (0xe0 <= c && c <= 0xef )) {
432
431
i += 2 ;
433
432
} else {
434
- i += 1 ;
433
+ printable = 0 ;
434
+ break ;
435
435
}
436
436
}
437
437
438
438
if (printable ) {
439
439
if (param_wrap_string_flag ) {
440
440
joutput ("new CobolDataStorage(" );
441
441
}
442
+
442
443
joutput ("\"" );
444
+
443
445
for (i = 0 ; i < size ; i ++ ) {
444
446
c = s [i ];
445
- if (c == '\"' || c == '\\' ) {
447
+ if (! output_multibyte && ( c == '\"' || c == '\\' ) ) {
446
448
joutput ("\\%c" , c );
447
- } else if (c == '\n' ) {
449
+ } else if (! output_multibyte && ( c == '\n' ) ) {
448
450
joutput ("\\n" );
449
451
} else {
450
452
joutput ("%c" , c );
451
453
}
454
+ output_multibyte = !output_multibyte &&
455
+ ((0x81 <= c && c <= 0x9f ) || (0xe0 <= c && c <= 0xef ));
452
456
}
457
+
453
458
joutput ("\"" );
459
+
454
460
if (param_wrap_string_flag ) {
455
461
joutput (")" );
456
462
}
457
463
} else {
458
464
joutput ("makeCobolDataStorage(" );
465
+
459
466
for (i = 0 ; i < size ; i ++ ) {
460
467
joutput ("(byte)0x%02x" , s [i ]);
461
468
if (i < size - 1 ) {
462
469
joutput (", " );
463
470
}
464
471
}
472
+
465
473
joutput (")" );
466
474
}
467
475
}
Original file line number Diff line number Diff line change 18
18
*/
19
19
package jp .osscons .opensourcecobol .libcobj .data ;
20
20
21
+ import java .io .UnsupportedEncodingException ;
21
22
import java .nio .ByteBuffer ;
22
23
import java .nio .ByteOrder ;
23
24
import jp .osscons .opensourcecobol .libcobj .common .CobolModule ;
@@ -180,7 +181,11 @@ public void memcpy(byte[] buf, int size) {
180
181
* @param size
181
182
*/
182
183
public void memcpy (String str , int size ) {
183
- this .memcpy (str .getBytes (), size );
184
+ try {
185
+ this .memcpy (str .getBytes ("SJIS" ), size );
186
+ } catch (UnsupportedEncodingException e ) {
187
+ this .memcpy (str .getBytes (), size );
188
+ }
184
189
}
185
190
186
191
/**
You can’t perform that action at this time.
0 commit comments