]> git.tdb.fi Git - libs/core.git/blobdiff - source/iso646fi.cpp
Rework the codec API completely to remove the internal buffering
[libs/core.git] / source / iso646fi.cpp
index 1874ded8cf9eefd309f6c62fbf1a0ce0ae3bed2b..cfdae24301a2bb886f31745669c404c8ce5734cd 100644 (file)
@@ -10,64 +10,73 @@ Distributed under the LGPL
 using namespace std;
 
 namespace Msp {
 using namespace std;
 
 namespace Msp {
+namespace Codecs {
 
 
-void Iso646Fi::Encoder::encode_char(wchar_t c_)
+void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf)
 {
 {
-       // Win32 has typedef unsigned short wchar_t
-       int c=c_;
-
-       if((c>=0 && c<=0x5A) || c==0x5F || (c>=0x61 && c<=0x7A))
-               append(c);
-       else if(c==0xC4)
-               append(0x5B);
-       else if(c==0xC5)
-               append(0x5D);
-       else if(c==0xD6)
-               append(0x5C);
-       else if(c==0xDC)
-               append(0x5E);
-       else if(c==0xE4)
-               append(0x7B);
-       else if(c==0xE5)
-               append(0x7D);
-       else if(c==0xE9)
-               append(0x60);
-       else if(c==0xF6)
-               append(0x7C);
-       else if(c==0xFC)
-               append(0x7E);
+       if((ch>=0 && ch<=0x5A) || ch==0x5F || (ch>=0x61 && ch<=0x7A))
+               buf+=ch;
+       else if(ch==0xC4)
+               buf+=0x5B;
+       else if(ch==0xC5)
+               buf+=0x5D;
+       else if(ch==0xD6)
+               buf+=0x5C;
+       else if(ch==0xDC)
+               buf+=0x5E;
+       else if(ch==0xE4)
+               buf+=0x7B;
+       else if(ch==0xE5)
+               buf+=0x7D;
+       else if(ch==0xE9)
+               buf+=0x60;
+       else if(ch==0xF6)
+               buf+=0x7C;
+       else if(ch==0xFC)
+               buf+=0x7E;
        else
        else
-               error("Can't express character in ISO-646-FI");
+               error(ch, buf, "Can't express character in ISO-646-FI");
 }
 
 }
 
-void Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
+void Iso646Fi::Encoder::transliterate(UnicodeChar, string &buf)
+{
+       buf+='?';
+}
+
+
+UnicodeChar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
 {
        if(i==str.end())
 {
        if(i==str.end())
-               return;
+               return error("No input");
 
 
-       unsigned char c=*i++;
-       if(c==0x5B)
-               append(0xC4);
-       else if(c==0x5C)
-               append(0xD6);
-       else if(c==0x5D)
-               append(0xC5);
-       else if(c==0x5E)
-               append(0xDC);
-       else if(c==0x60)
-               append(0xE9);
-       else if(c==0x7B)
-               append(0xE4);
-       else if(c==0x7C)
-               append(0xF6);
-       else if(c==0x7D)
-               append(0xE5);
-       else if(c==0x7E)
-               append(0xFC);
-       else if(c<=0x7F)
-               append(c);
+       unsigned char ch=*i;
+       UnicodeChar result=-1;
+       if(ch==0x5B)
+               result=0xC4;
+       else if(ch==0x5C)
+               result=0xD6;
+       else if(ch==0x5D)
+               result=0xC5;
+       else if(ch==0x5E)
+               result=0xDC;
+       else if(ch==0x60)
+               result=0xE9;
+       else if(ch==0x7B)
+               result=0xE4;
+       else if(ch==0x7C)
+               result=0xF6;
+       else if(ch==0x7D)
+               result=0xE5;
+       else if(ch==0x7E)
+               result=0xFC;
+       else if(ch<=0x7F)
+               result=ch;
        else
        else
-               error("Invalid ISO-646-FI string (undefined character)");
-}
+               result=error("Undefined ISO-646-FI character");
 
 
+       ++i;
+       return result;
 }
 }
+
+} // namespace Codecs
+} // namespace Msp