3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
10 #include "jisx0208.table"
17 void JisX0208::Encoder::encode_char(UnicodeChar ucs, string &buf)
19 unsigned short jis=ucs_to_jisx0208(ucs);
22 char jbuf[2]={jis>>8, jis};
26 error(ucs, buf, "Can't express character in JIS X 0208");
29 void JisX0208::Encoder::transliterate(UnicodeChar, string &buf)
35 UnicodeChar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
38 return error("No input");
40 string::const_iterator j=i;
46 result=error("Incomplete JIS X 0208 character");
50 result=jisx0208_to_ucs(jis);
52 result=error("Undefined JIS X 0208 character");
60 UnicodeChar jisx0208_to_ucs(Kuten jis)
62 if(jis.ku==0 || jis.ku>0x5E || jis.ten==0 || jis.ten>0x5E)
65 return jisx0208_to_ucs_table[jis.ku*94 + jis.ten - 95];
68 Kuten ucs_to_jisx0208(UnicodeChar c)
74 for(unsigned bit=0x1000; bit; bit>>=1)
76 if(i+bit>=ucs_to_jisx0208_table_size)
78 if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
83 if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
85 result.ku=(ucs_to_jisx0208_table[i].jis>>8)+1;
86 result.ten=ucs_to_jisx0208_table[i].jis+1;