]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/iso2022jp.cpp
Use C++11 features with containers
[libs/core.git] / source / stringcodec / iso2022jp.cpp
index 1e5bf90ee590fb068276a1287e3b0fe5c3a9f4ff..296c1efe1ed479bd930a8b7f768d87b9a970d010 100644 (file)
@@ -35,12 +35,14 @@ void Iso2022Jp::Encoder::encode_char(unichar ch, string &buf)
        {
                Kuten jis = ucs_to_jisx0208(ch);
                if(!jis)
-                       return error(ch, buf, "Can't express character in ISO-2022-JP");
+                       return error(ch, buf, invalid_character(ch, "ISO-2022-JP"));
 
                if(mode!=JISX0208)
                        switch_mode(JISX0208, buf);
 
-               char jbuf[2] = {jis.ku+0x20, jis.ten+0x20};
+               char jbuf[2];
+               jbuf[0] = jis.ku+0x20;
+               jbuf[1] = jis.ten+0x20;
                buf.append(jbuf, 2);
        }
 }
@@ -64,7 +66,7 @@ void Iso2022Jp::Encoder::switch_mode(Mode m, string &buf)
        case ASCII:    buf.append("\033(B", 3); break;
        case JISX0201: buf.append("\033(J", 3); break;
        case JISX0208: buf.append("\033$B", 3); break;
-       default: throw CodecError("WTF?  Invalid mode in Iso2022Jp::Encoder::switch_mode");
+       default: throw invalid_argument("Iso2022Jp::Encoder::switch_mode");
        }
 }
 
@@ -89,7 +91,7 @@ unichar Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterato
 
        while(i!=str.end())
        {
-               string::const_iterator j = i;
+               auto j = i;
 
                unichar result = -1;
                if(*j==033)
@@ -121,7 +123,7 @@ unichar Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterato
                else if(dec)
                        return dec->decode_char(str, i);
                else
-                       throw CodecError("WTF?  No sub-decoder for Iso2022Jp::Decoder");
+                       throw logic_error("no sub-decoder");
 
                if(result>=0)
                        return result;