]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/codec.cpp
Add move semantics to Variant
[libs/core.git] / source / stringcodec / codec.cpp
index 21ddf8a7307ff8071551f4eb0473dfff48f05898..ff2bd63d5e657b8547392163d12aa50b94f40e13 100644 (file)
@@ -20,7 +20,7 @@ bool Codec::detect(const string &str) const
        Decoder *dec = create_decoder(IGNORE_ERRORS);
 
        bool result = true;
-       for(string::const_iterator i=str.begin(); (result && i!=str.end()); )
+       for(auto i=str.begin(); (result && i!=str.end()); )
                result = (dec->decode_char(str, i)!=-1);
 
        delete dec;
@@ -30,8 +30,8 @@ bool Codec::detect(const string &str) const
 
 void Codec::Encoder::encode(const ustring &str, string &buf)
 {
-       for(ustring::const_iterator i=str.begin(); i!=str.end(); ++i)
-               encode_char(*i, buf);
+       for(unichar c: str)
+               encode_char(c, buf);
 }
 
 string Codec::Encoder::encode(const ustring &str)
@@ -46,7 +46,7 @@ string Codec::Encoder::encode(const ustring &str)
 
 void Codec::Decoder::decode(const string &str, ustring &buf)
 {
-       for(string::const_iterator i=str.begin(); i!=str.end();)
+       for(auto i=str.begin(); i!=str.end();)
        {
                unichar c = decode_char(str, i);
                if(c!=-1)
@@ -86,7 +86,7 @@ Codec *create_codec(const string &n)
                else if(em_str=="trans" || em_str=="transliterate")
                        em = TRANSLITERATE;
                else
-                       throw invalid_argument("invalid error mode");
+                       throw invalid_argument("StringCodec::create_codec");
        }
 
        if(name=="ascii") return new Ascii(em);
@@ -101,7 +101,7 @@ Codec *create_codec(const string &n)
        if(name=="utf16be") return new Utf16(em, Utf16::BIG);
        if(name=="utf16le") return new Utf16(em, Utf16::LITTLE);
        if(name=="windows1252" || name=="cp1252") return new Windows1252(em);
-       throw invalid_argument("unknown string codec");
+       throw invalid_argument("StringCodec::create_codec");
 }
 
 Codec *detect_codec(const string &str)
@@ -111,9 +111,8 @@ Codec *detect_codec(const string &str)
        bool is_latin1 = true;
        unsigned utf8_mb = 0;
 
-       for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
+       for(char c: str)
        {
-               unsigned char c = *i;
                if(c&0x80)
                {
                        is_ascii = false;