]> git.tdb.fi Git - libs/core.git/blobdiff - source/jisx0201.cpp
Rework the codec API completely to remove the internal buffering
[libs/core.git] / source / jisx0201.cpp
index 49f8b00240463af63b761220df1460c8c079270c..9c1e92938bb7700b7b1587bc03d321e284653a85 100644 (file)
@@ -10,39 +10,49 @@ Distributed under the LGPL
 using namespace std;
 
 namespace Msp {
 using namespace std;
 
 namespace Msp {
+namespace Codecs {
 
 
-void JisX0201::Encoder::encode_char(wchar_t c_)
+void JisX0201::Encoder::encode_char(UnicodeChar ch, string &buf)
 {
 {
-       // Win32 has typedef unsigned short wchar_t
-       int c=c_;
-       if(c>=0 && c<=0x7F && c!=0x5C && c!=0x7E)
-               append(c);
-       else if(c==0xA5)
-               append(0x5C);
-       else if(c==0x203E)
-               append(0x7E);
-       else if(c>=0xFF61 && c<=0xFF9F)
-               append(c-0xFEC0);
+       if(ch>=0 && ch<=0x7F && ch!=0x5C && ch!=0x7E)
+               buf+=ch;
+       else if(ch==0xA5)
+               buf+=0x5C;
+       else if(ch==0x203E)
+               buf+=0x7E;
+       else if(ch>=0xFF61 && ch<=0xFF9F)
+               buf+=ch-0xFEC0;
        else
        else
-               error("Can't express character in JIS X 0201");
+               error(ch, buf, "Can't express character in JIS X 0201");
 }
 
 }
 
-void JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i)
+void JisX0201::Encoder::transliterate(UnicodeChar, string &buf)
+{
+       buf+='?';
+}
+
+
+UnicodeChar JisX0201::Decoder::decode_char(const string &str, string::const_iterator &i)
 {
        if(i==str.end())
 {
        if(i==str.end())
-               return;
-
-       unsigned char c=*i++;
-       if(c==0x5C)
-               append(0xA5);
-       else if(c==0x7E)
-               append(0x203E);
-       else if(c<=0x7F)
-               append(c);
-       else if(c>=0xA1 && c<=0xDF)
-               append(c+0xFEC0);
+               return error("No input");
+
+       unsigned char ch=*i;
+       UnicodeChar result;
+       if(ch==0x5C)
+               result=0xA5;
+       else if(ch==0x7E)
+               result=0x203E;
+       else if(ch<=0x7F)
+               result=ch;
+       else if(ch>=0xA1 && ch<=0xDF)
+               result=ch+0xFEC0;
        else
        else
-               error("Invalid JIS X 0201 string (undefined character)");
+               result=error("Undefined JIS X 0201 character");
+
+       ++i;
+       return result;
 }
 
 }
 
+} // namespace Codecs
 } // namespace Msp
 } // namespace Msp