3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
10 #include "jisx0208.table"
16 void JisX0208::Encoder::encode_char(wchar_t ucs)
18 unsigned short jis=ucs_to_jisx0208(ucs);
21 char buf[2]={jis>>8, jis};
25 error("Can't express character in JIS X 0208");
29 void JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
40 wchar_t ucs=jisx0208_to_ucs(high<<8 | *i++);
46 error("Invalid JIS X 0208 string (undefined character)");
49 void JisX0208::Decoder::sync()
53 error("Sync in middle of JIS X 0208 character");
58 wchar_t jisx0208_to_ucs(unsigned short jis)
60 if((jis&0xFF)<0x21 || (jis&0xFF)>0x7E || (jis&0xFF00)<0x2100 || (jis&0xFF00)>0x7E00)
63 return jisx0208_to_ucs_table[((jis>>8)&0xFF)*94 + (jis&0xFF)-0x21*95];
66 unsigned short ucs_to_jisx0208(wchar_t c)
68 if(c&0xFFFF0000) return 0;
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))
79 if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
80 return ucs_to_jisx0208_table[i].jis;