@@ -436,15 +436,24 @@ rb_cp50221_encoder = {
436
436
437
437
/* JIS0201 to JIS0208 conversion table */
438
438
enum {tbl0208_num = 0xDF - 0xA1 + 1};
439
- static const char tbl0208[2 * tbl0208_num] =
440
- "\x21\x23\x21\x56\x21\x57\x21\x22\x21\x26\x25\x72\x25\x21\x25\x23" \
441
- "\x25\x25\x25\x27\x25\x29\x25\x63\x25\x65\x25\x67\x25\x43\x21\x3C" \
442
- "\x25\x22\x25\x24\x25\x26\x25\x28\x25\x2A\x25\x2B\x25\x2D\x25\x2F" \
443
- "\x25\x31\x25\x33\x25\x35\x25\x37\x25\x39\x25\x3B\x25\x3D\x25\x3F" \
444
- "\x25\x41\x25\x44\x25\x46\x25\x48\x25\x4A\x25\x4B\x25\x4C\x25\x4D" \
445
- "\x25\x4E\x25\x4F\x25\x52\x25\x55\x25\x58\x25\x5B\x25\x5E\x25\x5F" \
446
- "\x25\x60\x25\x61\x25\x62\x25\x64\x25\x66\x25\x68\x25\x69\x25\x6A" \
447
- "\x25\x6B\x25\x6C\x25\x6D\x25\x6F\x25\x73\x21\x2B\x21\x2C";
439
+ static const char tbl0208[tbl0208_num][2] = {
440
+ "\x21\x23", "\x21\x56", "\x21\x57", "\x21\x22",
441
+ "\x21\x26", "\x25\x72", "\x25\x21", "\x25\x23",
442
+ "\x25\x25", "\x25\x27", "\x25\x29", "\x25\x63",
443
+ "\x25\x65", "\x25\x67", "\x25\x43", "\x21\x3C",
444
+ "\x25\x22", "\x25\x24", "\x25\x26", "\x25\x28",
445
+ "\x25\x2A", "\x25\x2B", "\x25\x2D", "\x25\x2F",
446
+ "\x25\x31", "\x25\x33", "\x25\x35", "\x25\x37",
447
+ "\x25\x39", "\x25\x3B", "\x25\x3D", "\x25\x3F",
448
+ "\x25\x41", "\x25\x44", "\x25\x46", "\x25\x48",
449
+ "\x25\x4A", "\x25\x4B", "\x25\x4C", "\x25\x4D",
450
+ "\x25\x4E", "\x25\x4F", "\x25\x52", "\x25\x55",
451
+ "\x25\x58", "\x25\x5B", "\x25\x5E", "\x25\x5F",
452
+ "\x25\x60", "\x25\x61", "\x25\x62", "\x25\x64",
453
+ "\x25\x66", "\x25\x68", "\x25\x69", "\x25\x6A",
454
+ "\x25\x6B", "\x25\x6C", "\x25\x6D", "\x25\x6F",
455
+ "\x25\x73", "\x21\x2B", "\x21\x2C"
456
+ };
448
457
449
458
static ssize_t
450
459
fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
@@ -455,17 +464,19 @@ fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
455
464
456
465
if (sp[0] == G0_JISX0201_KATAKANA && sp[2]) {
457
466
int c = sp[2] & 0x7F;
458
- const char *p = tbl0208 + ( c - 0x21) * 2 ;
467
+ const char *p = tbl0208[ c - 0x21] ;
459
468
sp[2] = 0;
460
469
o = iso2022jp_put_state(sp, o, sp[1], G0_JISX0208_1983);
461
470
sp[0] = G0_JISX0208_1983;
462
471
*o++ = *p++;
463
472
if (l == 2 && s[0] == 0x8E) {
464
473
if (s[1] == 0xDE) {
474
+ /* VOICED SOUND MARK */
465
475
*o++ = *p + 1;
466
476
return o - output0;
467
477
}
468
478
else if (s[1] == 0xDF && (0x4A <= c && c <= 0x4E)) {
479
+ /* SEMI-VOICED SOUND MARK */
469
480
*o++ = *p + 2;
470
481
return o - output0;
471
482
}
@@ -477,7 +488,8 @@ fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
477
488
if ((0xA1 <= s[1] && s[1] <= 0xB5) ||
478
489
(0xC5 <= s[1] && s[1] <= 0xC9) ||
479
490
(0xCF <= s[1] && s[1] <= 0xDF)) {
480
- const char *p = tbl0208 + (s[1] - 0xA1) * 2;
491
+ /* May not be followed by a sound mark */
492
+ const char *p = tbl0208[s[1] - 0xA1];
481
493
o = iso2022jp_put_state(sp, o, *sp, G0_JISX0208_1983);
482
494
*o++ = *p++;
483
495
*o++ = *p;
@@ -491,6 +503,7 @@ fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
491
503
return o - output0;
492
504
}
493
505
506
+ /* Katakana that may be followed by a sound mark */
494
507
sp[2] = s[1];
495
508
sp[1] = sp[0];
496
509
sp[0] = G0_JISX0201_KATAKANA;
@@ -512,7 +525,7 @@ finish_cp50220_encoder(void *statep, unsigned char *o, size_t osize)
512
525
513
526
if (sp[0] == G0_JISX0201_KATAKANA && sp[2]) {
514
527
int c = sp[2] & 0x7F;
515
- const char *p = tbl0208 + ( c - 0x21) * 2 ;
528
+ const char *p = tbl0208[ c - 0x21] ;
516
529
o = iso2022jp_put_state(sp, o, sp[1], G0_JISX0208_1983);
517
530
sp[0] = G0_JISX0208_1983;
518
531
*o++ = *p++;
@@ -549,4 +562,3 @@ TRANS_INIT(iso2022)
549
562
rb_register_transcoder(&rb_cp50220_encoder);
550
563
rb_register_transcoder(&rb_cp50221_encoder);
551
564
}
552
-
0 commit comments