nkf with conversion between jisx0213 and utf-8
Revision | 647dc310ae01e9d1fd199128e29ab0965a040124 (tree) |
---|---|
Time | 2012-11-11 10:25:34 |
Author | KIHARA Hideto <deton@user...> |
Commiter | KIHARA Hideto |
Add is_x0213_2_in_x0212() to avoid wrong conversion for jisx0212 chars (ex: cb9a) from utf-8 to euc-jisx0213 without --cp932inv.
But jisx0212 chars are lost without --cp932inv.
@@ -1565,13 +1565,26 @@ x0212_unshift(nkf_char c) | ||
1565 | 1565 | } |
1566 | 1566 | #endif /* X0212_ENABLE */ |
1567 | 1567 | |
1568 | +static int | |
1569 | +is_x0213_2_in_x0212(nkf_char c1) | |
1570 | +{ | |
1571 | + static const char x0213_2_table[] = | |
1572 | + {0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1}; | |
1573 | + int ku = c1 - 0x20; | |
1574 | + if (ku <= 15) | |
1575 | + return x0213_2_table[ku]; /* 1, 3-5, 8, 12-15 */ | |
1576 | + if (78 <= ku && ku <= 94) | |
1577 | + return 1; | |
1578 | + return 0; | |
1579 | +} | |
1580 | + | |
1568 | 1581 | static nkf_char |
1569 | 1582 | e2s_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1) |
1570 | 1583 | { |
1571 | 1584 | nkf_char ndx; |
1572 | 1585 | if (is_eucg3(c2)){ |
1573 | 1586 | ndx = c2 & 0x7f; |
1574 | - if (x0213_f){ | |
1587 | + if (x0213_f && is_x0213_2_in_x0212(ndx)){ | |
1575 | 1588 | if((0x21 <= ndx && ndx <= 0x2F)){ |
1576 | 1589 | if (p2) *p2 = ((ndx - 1) >> 1) + 0xec - ndx / 8 * 3; |
1577 | 1590 | if (p1) *p1 = c1 + ((ndx & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e); |