X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fstringcodec%2Fjisx0201.cpp;fp=source%2Fstringcodec%2Fjisx0201.cpp;h=d3fe635ce90beda61e2f99cc8aef5fc88e0794e0;hb=b42ed73a1b241c0e93ee03c43c4584b41c549bac;hp=0000000000000000000000000000000000000000;hpb=5b1368cb791cab043f0435628cacbaff36e39b7b;p=libs%2Fcore.git diff --git a/source/stringcodec/jisx0201.cpp b/source/stringcodec/jisx0201.cpp new file mode 100644 index 0000000..d3fe635 --- /dev/null +++ b/source/stringcodec/jisx0201.cpp @@ -0,0 +1,58 @@ +/* $Id$ + +This file is part of libmspstrings +Copyright © 2006-2007 Mikko Rasa +Distributed under the LGPL +*/ + +#include "jisx0201.h" + +using namespace std; + +namespace Msp { +namespace Codecs { + +void JisX0201::Encoder::encode_char(UnicodeChar ch, string &buf) +{ + if(ch>=0 && ch<=0x7F && ch!=0x5C && ch!=0x7E) + buf += ch; + else if(ch==0xA5) + buf += 0x5C; + else if(ch==0x203E) + buf += 0x7E; + else if(ch>=0xFF61 && ch<=0xFF9F) + buf += ch-0xFEC0; + else + error(ch, buf, "Can't express character in JIS X 0201"); +} + +void JisX0201::Encoder::transliterate(UnicodeChar, string &buf) +{ + buf += '?'; +} + + +UnicodeChar JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i) +{ + if(i==str.end()) + return error("No input"); + + unsigned char ch = *i; + UnicodeChar result; + if(ch==0x5C) + result = 0xA5; + else if(ch==0x7E) + result = 0x203E; + else if(ch<=0x7F) + result = ch; + else if(ch>=0xA1 && ch<=0xDF) + result = ch+0xFEC0; + else + result = error("Undefined JIS X 0201 character"); + + ++i; + return result; +} + +} // namespace Codecs +} // namespace Msp