using namespace std;
namespace Msp {
-namespace Codecs {
+namespace StringCodec {
-void JisX0208::Encoder::encode_char(UnicodeChar ucs, string &buf)
+void JisX0208::Encoder::encode_char(unichar ucs, string &buf)
{
unsigned short jis = ucs_to_jisx0208(ucs);
if(jis)
{
- char jbuf[2] = {jis>>8, jis};
+ char jbuf[2];
+ jbuf[0] = jis>>8;
+ jbuf[1] = jis;
buf.append(jbuf, 2);
}
else
- error(ucs, buf, "Can't express character in JIS X 0208");
+ error(ucs, buf, invalid_character(ucs, "JIS X 0208"));
}
-void JisX0208::Encoder::transliterate(UnicodeChar, string &buf)
+void JisX0208::Encoder::transliterate(unichar, string &buf)
{
buf.append("!)", 2);
}
-UnicodeChar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
+unichar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i)
{
if(i==str.end())
- return error("No input");
+ return -1;
string::const_iterator j = i;
Kuten jis;
jis.ku = *j++-0x20;
- UnicodeChar result;
+ unichar result;
if(j==str.end())
- result = error("Incomplete JIS X 0208 character");
+ result = error(invalid_sequence(i, j, "incomplete JIS X 0208 character"));
else
{
jis.ten = *j++-0x20;
result = jisx0208_to_ucs(jis);
+ if(result==-1)
+ result = error(invalid_sequence(i, j, "invalid JIS X 0208 ku-ten"));
if(result==0)
- result = error("Undefined JIS X 0208 character");
+ result = error(invalid_sequence(i, j, "undefined JIS X 0208 character"));
}
i = j;
}
-UnicodeChar jisx0208_to_ucs(Kuten jis)
+unichar jisx0208_to_ucs(Kuten jis)
{
if(jis.ku==0 || jis.ku>0x5E || jis.ten==0 || jis.ten>0x5E)
- return 0;
+ return -1;
return jisx0208_to_ucs_table[jis.ku*94 + jis.ten - 95];
}
-Kuten ucs_to_jisx0208(UnicodeChar c)
+Kuten ucs_to_jisx0208(unichar c)
{
if(c<0 || c>0xFFFF)
return Kuten();
return result;
}
-} // namespace Codecs
+} // namespace StringCodec
} // namespace Msp