]> git.tdb.fi Git - libs/core.git/blobdiff - source/iso2022jp.cpp
Added reset function for StringCodec::Decoder
[libs/core.git] / source / iso2022jp.cpp
index 6f83bd95645ae543117dee6146c5e8b6a3bcf7bc..ab31456245b449c861a4c69b98dab62af77d4f40 100644 (file)
@@ -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<unsigned char>(*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());