]> git.tdb.fi Git - libs/core.git/commitdiff
Return -1 from decode_char if there is no input
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 Jun 2011 18:16:19 +0000 (21:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Jun 2011 17:55:38 +0000 (20:55 +0300)
Improve the logic in some decoders

source/stringcodec/ascii.cpp
source/stringcodec/iso2022jp.cpp
source/stringcodec/iso646fi.cpp
source/stringcodec/iso88591.cpp
source/stringcodec/iso885915.cpp
source/stringcodec/jisx0201.cpp
source/stringcodec/jisx0208.cpp
source/stringcodec/utf8.cpp
source/stringcodec/windows1252.cpp

index 9867049a14b6ea03be91d3f4724d97b0b728c080..fa5ce7f1cdfc0cd4eeb8b931a0f1c42aa0dc26a4 100644 (file)
@@ -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");
index 985451280f42cfd79496963a95716dd59b3d717d..1e5bf90ee590fb068276a1287e3b0fe5c3a9f4ff 100644 (file)
@@ -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())
        {
index ee7705b36898caec0af5d5b81724076828a8559a..64e429d4197a648349edbda2f8bc88d5df070454 100644 (file)
@@ -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;
index cdb5f484a2f7532d1987828971dc37336c69f83e..9adc2d9e09bf7423d650b78c66409a0e8c9bbbcf 100644 (file)
@@ -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<unsigned char>(*i++);
 }
index 3e71f753afcfdfdc6ce1c57c75378cb1f01c9cad..8dfc3a1e91a5c178e26461d686ea1bb340f76ce9 100644 (file)
@@ -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
index 307a681fdbcea1a42f8a4bed5b021e67a687ddb7..4d9d6bdf5eaea9c257a13325643c574b1672761d 100644 (file)
@@ -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;
index 6f07d05aac044065146d5d806a3ee30847309c78..411ae2b6477c945e5d5a95da14837e42863d2591 100644 (file)
@@ -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;
index f56ba546064ee0c234f8d47af5a2d4fc25d0fb04..b0431eb4f49e3d595ddefd44e5dfca57e421d060 100644 (file)
@@ -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)
        {
index 531860bca47331a94f2dcae77be1f240573ac209..72eb104115db192cce202802d479a4d0e592beff 100644 (file)
@@ -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<unsigned char>(*i);
        unichar result;