3 #include "jisx0208.table"
8 namespace StringCodec {
10 void JisX0208::Encoder::encode_char(unichar ucs, string &buf)
12 Kuten jis = ucs_to_jisx0208(ucs);
16 jbuf[0] = jis.ku+0x20;
17 jbuf[1] = jis.ten+0x20;
21 error(ucs, buf, invalid_character(ucs, "JIS X 0208"));
24 void JisX0208::Encoder::transliterate(unichar, string &buf)
30 unichar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
41 result = error(invalid_sequence(i, j, "incomplete JIS X 0208 character"));
45 result = jisx0208_to_ucs(jis);
47 result = error(invalid_sequence(i, j, "invalid JIS X 0208 ku-ten"));
49 result = error(invalid_sequence(i, j, "undefined JIS X 0208 character"));
57 unichar jisx0208_to_ucs(Kuten jis)
59 if(jis.ku==0 || jis.ku>0x5E || jis.ten==0 || jis.ten>0x5E)
62 return jisx0208_to_ucs_table[jis.ku*94 + jis.ten - 95];
65 Kuten ucs_to_jisx0208(unichar c)
71 for(unsigned bit=0x1000; bit; bit>>=1)
73 if(i+bit>=ucs_to_jisx0208_table_size)
75 if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
80 if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
82 result.ku = (ucs_to_jisx0208_table[i].jis>>8);
83 result.ten = ucs_to_jisx0208_table[i].jis;
89 } // namespace StringCodec