X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fiso2022jp.cpp;h=ab31456245b449c861a4c69b98dab62af77d4f40;hb=51b84c0c2c3abb0cf7e815c5ae259face40ac977;hp=6f83bd95645ae543117dee6146c5e8b6a3bcf7bc;hpb=58384e355b4a78730d69243f1092e47591f2f384;p=libs%2Fcore.git diff --git a/source/iso2022jp.cpp b/source/iso2022jp.cpp index 6f83bd9..ab31456 100644 --- a/source/iso2022jp.cpp +++ b/source/iso2022jp.cpp @@ -37,9 +37,18 @@ void Iso2022Jp::Encoder::encode_char(wchar_t c) throw CodecError("Can't express character in ISO-2022-JP"); if(mode!=JISX0208) switch_mode(JISX0208); + + char buf[2]={jis>>8, jis}; + append(buf, 2); } } +void Iso2022Jp::Encoder::sync() +{ + if(mode!=ASCII) + switch_mode(ASCII); +} + void Iso2022Jp::Encoder::switch_mode(Mode m) { mode=m; @@ -63,7 +72,7 @@ void Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterator & { if(escape) { - escape=escape<<8 | (unsigned char)*i; + escape=escape<<8 | static_cast(*i); if(*i>='@' && *i<='Z') { switch(escape) @@ -101,6 +110,12 @@ void Iso2022Jp::Decoder::sync() dec->flush(); } +void Iso2022Jp::Decoder::reset() +{ + switch_mode(ASCII); + escape=0; +} + void Iso2022Jp::Decoder::switch_mode(Mode m) { append(dec->get());