3 #include "jisx0208.table"
8 namespace StringCodec {
10 void JisX0208::Encoder::encode_char(UnicodeChar ucs, string &buf)
12 unsigned short jis = ucs_to_jisx0208(ucs);
15 char jbuf[2] = {jis>>8, jis};
19 error(ucs, buf, "Can't express character in JIS X 0208");
22 void JisX0208::Encoder::transliterate(UnicodeChar, string &buf)
28 UnicodeChar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
31 return error("No input");
33 string::const_iterator j = i;
39 result = error("Incomplete JIS X 0208 character");
43 result = jisx0208_to_ucs(jis);
45 result = error("Undefined JIS X 0208 character");
53 UnicodeChar jisx0208_to_ucs(Kuten jis)
55 if(jis.ku==0 || jis.ku>0x5E || jis.ten==0 || jis.ten>0x5E)
58 return jisx0208_to_ucs_table[jis.ku*94 + jis.ten - 95];
61 Kuten ucs_to_jisx0208(UnicodeChar c)
67 for(unsigned bit=0x1000; bit; bit>>=1)
69 if(i+bit>=ucs_to_jisx0208_table_size)
71 if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
76 if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
78 result.ku = (ucs_to_jisx0208_table[i].jis>>8)+1;
79 result.ten = ucs_to_jisx0208_table[i].jis+1;
85 } // namespace StringCodec