]> git.tdb.fi Git - libs/core.git/commitdiff
Avoid using an exception in a non-error situation
authorMikko Rasa <tdb@tdb.fi>
Mon, 6 Jun 2011 20:33:29 +0000 (23:33 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 6 Jun 2011 20:33:29 +0000 (23:33 +0300)
source/stringcodec/codec.cpp

index a342242402beaf65b8aafb4e9eee29b0af20550d..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;