From 93bb92bad766d269a6bac87e00020a6158531739 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 6 Jun 2011 23:33:29 +0300 Subject: [PATCH] Avoid using an exception in a non-error situation --- source/stringcodec/codec.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/source/stringcodec/codec.cpp b/source/stringcodec/codec.cpp index a342242..3dc4f9a 100644 --- a/source/stringcodec/codec.cpp +++ b/source/stringcodec/codec.cpp @@ -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; -- 2.43.0