}
+
namespace Msp {
+namespace Codecs {
-void Windows1252::Encoder::encode_char(wchar_t c_)
+void Windows1252::Encoder::encode_char(UnicodeChar ch, string &buf)
{
- int c=c_;
- if((c>=0 && c<=0x7F) || (c>=0xA0 && c<=0xFF))
- append(c);
+ if((ch>=0 && ch<=0x7F) || (ch>=0xA0 && ch<=0xFF))
+ buf += ch;
else
{
- unsigned i;
- for(i=0; i<32; ++i)
- if(table[i]==c)
+ for(unsigned i=0; i<32; ++i)
+ if(table[i]==ch)
{
- append(c);
- break;
+ buf += ch;
+ return;
}
-
- if(i==32)
- error("Can't express character in Windows-1252");
+
+ error(ch, buf, "Can't express character in Windows-1252");
}
}
-void Windows1252::Decoder::decode_char(const string &str, string::const_iterator &i)
+void Windows1252::Encoder::transliterate(UnicodeChar, string &buf)
+{
+ buf += '?';
+}
+
+
+UnicodeChar Windows1252::Decoder::decode_char(const string &str, string::const_iterator &i)
{
if(i==str.end())
- return;
- else
+ return error("No input");
+
+ int ch = static_cast<unsigned char>(*i);
+ UnicodeChar result;
+ if(ch>=0x80 && ch<=0x9F)
{
- int c=static_cast<unsigned char>(*i++);
- if(c>=0x80 && c<=0x9F)
- {
- c-=0x80;
- if(table[c]==0)
- error("Invalid Windows-1252 string (undefined character)");
- append(table[c]);
- }
- else
- append(c);
+ result = table[ch-0x80];
+ if(result==0)
+ result = error("Undefined Windows-1252 character");
}
+ else
+ result = ch;
+
+ ++i;
+ return result;
}
+} // namespace Codecs
} // namespace Msp