From: Mikko Rasa Date: Sat, 4 Jun 2011 18:16:19 +0000 (+0300) Subject: Return -1 from decode_char if there is no input X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3e3868860d4f4ca1bbe55fbf271c804307cea3c9;p=libs%2Fcore.git Return -1 from decode_char if there is no input Improve the logic in some decoders --- diff --git a/source/stringcodec/ascii.cpp b/source/stringcodec/ascii.cpp index 9867049..fa5ce7f 100644 --- a/source/stringcodec/ascii.cpp +++ b/source/stringcodec/ascii.cpp @@ -91,7 +91,7 @@ void Ascii::Encoder::transliterate(unichar ch, string &buf) unichar Ascii::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; else if(*i&0x80) { unichar result = error("Undefined ASCII character"); diff --git a/source/stringcodec/iso2022jp.cpp b/source/stringcodec/iso2022jp.cpp index 9854512..1e5bf90 100644 --- a/source/stringcodec/iso2022jp.cpp +++ b/source/stringcodec/iso2022jp.cpp @@ -85,7 +85,7 @@ Iso2022Jp::Decoder::Decoder(ErrorMode em): unichar Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; while(i!=str.end()) { diff --git a/source/stringcodec/iso646fi.cpp b/source/stringcodec/iso646fi.cpp index ee7705b..64e429d 100644 --- a/source/stringcodec/iso646fi.cpp +++ b/source/stringcodec/iso646fi.cpp @@ -44,16 +44,14 @@ void Iso646Fi::Encoder::transliterate(unichar, string &buf) unichar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; unsigned char ch = *i; - int tch = (ch<=0x7F ? transform_mapping_or_direct(mapping, map_size, ch, true) : -1); - unichar result; - if(tch==-1) + if(ch>=0x80) result = error("Undefined ISO-646-FI character"); else - result = tch; + result = transform_mapping_or_direct(mapping, map_size, ch, true); ++i; return result; diff --git a/source/stringcodec/iso88591.cpp b/source/stringcodec/iso88591.cpp index cdb5f48..9adc2d9 100644 --- a/source/stringcodec/iso88591.cpp +++ b/source/stringcodec/iso88591.cpp @@ -22,7 +22,7 @@ void Iso88591::Encoder::transliterate(unichar, string &buf) unichar Iso88591::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; return static_cast(*i++); } diff --git a/source/stringcodec/iso885915.cpp b/source/stringcodec/iso885915.cpp index 3e71f75..8dfc3a1 100644 --- a/source/stringcodec/iso885915.cpp +++ b/source/stringcodec/iso885915.cpp @@ -44,19 +44,10 @@ void Iso885915::Encoder::transliterate(unichar, string &buf) unichar Iso885915::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; - unsigned char ch = *i; - int tch = transform_mapping_or_direct(mapping, map_size, ch, true); - - unichar result; - if(tch==-1) - result = error("Undefined ISO-8859-15 character"); - else - result = tch; - - ++i; - return result; + unsigned char ch = *i++; + return transform_mapping_or_direct(mapping, map_size, ch, true); } } // namespace StringCodec diff --git a/source/stringcodec/jisx0201.cpp b/source/stringcodec/jisx0201.cpp index 307a681..4d9d6bd 100644 --- a/source/stringcodec/jisx0201.cpp +++ b/source/stringcodec/jisx0201.cpp @@ -28,7 +28,7 @@ void JisX0201::Encoder::transliterate(unichar, string &buf) unichar JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; unsigned char ch = *i; unichar result; diff --git a/source/stringcodec/jisx0208.cpp b/source/stringcodec/jisx0208.cpp index 6f07d05..411ae2b 100644 --- a/source/stringcodec/jisx0208.cpp +++ b/source/stringcodec/jisx0208.cpp @@ -28,7 +28,7 @@ void JisX0208::Encoder::transliterate(unichar, string &buf) unichar JisX0208::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; string::const_iterator j = i; Kuten jis; diff --git a/source/stringcodec/utf8.cpp b/source/stringcodec/utf8.cpp index f56ba54..b0431eb 100644 --- a/source/stringcodec/utf8.cpp +++ b/source/stringcodec/utf8.cpp @@ -44,7 +44,7 @@ void Utf8::Encoder::transliterate(unichar, string &buf) unichar Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; if((*i&0xC0)==0x80) { diff --git a/source/stringcodec/windows1252.cpp b/source/stringcodec/windows1252.cpp index 531860b..72eb104 100644 --- a/source/stringcodec/windows1252.cpp +++ b/source/stringcodec/windows1252.cpp @@ -44,7 +44,7 @@ void Windows1252::Encoder::transliterate(unichar, string &buf) unichar Windows1252::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; int ch = static_cast(*i); unichar result;