]> git.tdb.fi Git - libs/core.git/blobdiff - source/ascii.cpp
More sophisticated error handling
[libs/core.git] / source / ascii.cpp
index 10eb7949b713d14e49d621b568cd205760a21aa7..43f7053173a21e1ac5cc3b79bc3cdad3def303de 100644 (file)
@@ -4,11 +4,14 @@ using namespace std;
 
 namespace Msp {
 
 
 namespace Msp {
 
-void Ascii::Encoder::encode_char(wchar_t c)
+void Ascii::Encoder::encode_char(wchar_t c_)
 {
 {
+       // Win32 has typedef unsigned short wchar_t
+       int c=c_;
        if(c<0 || c>0x7F)
        if(c<0 || c>0x7F)
-               throw CodecError("Can't express character in ASCII");
-       append(c);
+               error("Can't express character in ASCII");
+       else
+               append(c);
 }
 
 
 }
 
 
@@ -16,9 +19,13 @@ void Ascii::Decoder::decode_char(const string &str, string::const_iterator &i)
 {
        if(i==str.end())
                return;
 {
        if(i==str.end())
                return;
-       if(*i&0x80)
-               throw CodecError("Invalid ASCII string (undefined character)");
-       append(*i++);
+       else if(*i&0x80)
+       {
+               error("Invalid ASCII string (undefined character)");
+               ++i;
+       }
+       else
+               append(*i++);
 }
 
 } // namespace Msp
 }
 
 } // namespace Msp