3 #include "jisx0208.table"
8 namespace StringCodec {
10 void JisX0208::Encoder::encode_char(unichar ucs, string &buf)
12 unsigned short jis = ucs_to_jisx0208(ucs);
15 char jbuf[2] = {jis>>8, jis};
19 error(ucs, buf, invalid_character(ucs, "JIS X 0208"));
22 void JisX0208::Encoder::transliterate(unichar, string &buf)
28 unichar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
33 string::const_iterator j = i;
39 result = error(invalid_sequence(i, j, "incomplete JIS X 0208 character"));
43 result = jisx0208_to_ucs(jis);
45 result = error(invalid_sequence(i, j, "invalid JIS X 0208 ku-ten"));
47 result = error(invalid_sequence(i, j, "undefined JIS X 0208 character"));
55 unichar jisx0208_to_ucs(Kuten jis)
57 if(jis.ku==0 || jis.ku>0x5E || jis.ten==0 || jis.ten>0x5E)
60 return jisx0208_to_ucs_table[jis.ku*94 + jis.ten - 95];
63 Kuten ucs_to_jisx0208(unichar c)
69 for(unsigned bit=0x1000; bit; bit>>=1)
71 if(i+bit>=ucs_to_jisx0208_table_size)
73 if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
78 if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
80 result.ku = (ucs_to_jisx0208_table[i].jis>>8)+1;
81 result.ten = ucs_to_jisx0208_table[i].jis+1;
87 } // namespace StringCodec