]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/codec.cpp
Avoid using an exception in a non-error situation
[libs/core.git] / source / stringcodec / codec.cpp
index b7c600d74d6fbf0c70ccfd5fed9b766bd96a1c56..3dc4f9a9d452efe7aef2478878d36ad3977af170 100644 (file)
@@ -16,17 +16,11 @@ namespace StringCodec {
 
 bool Codec::detect(const string &str) const
 {
-       Decoder *dec = create_decoder();
+       Decoder *dec = create_decoder(IGNORE_ERRORS);
+
        bool result = true;
-       try
-       {
-               for(string::const_iterator i=str.begin(); i!=str.end(); )
-                       dec->decode_char(str, i);
-       }
-       catch(const CodecError &)
-       {
-               result = false;
-       }
+       for(string::const_iterator i=str.begin(); (result && i!=str.end()); )
+               result = (dec->decode_char(str, i)!=-1);
 
        delete dec;
 
@@ -83,7 +77,7 @@ unichar Codec::Decoder::error(const string &msg)
        switch(err_mode)
        {
        case TRANSLITERATE:
-               return 0xFFFE;
+               return 0xFFFD;
        case IGNORE_ERRORS:
                return -1;
        default: