X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fwindows1252.cpp;h=d809c3ff9bad7616a0e053f600edd72f2a207866;hp=db9d417685b9c9314a616ac69854a9ea32ff9562;hb=f47bc86e6ce900c5323e593db003c93110538268;hpb=79d472ad3fde75de2eba2487579b047d35e56978 diff --git a/source/windows1252.cpp b/source/windows1252.cpp index db9d417..d809c3f 100644 --- a/source/windows1252.cpp +++ b/source/windows1252.cpp @@ -22,44 +22,50 @@ unsigned short table[32]= } 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(*i); + UnicodeChar result; + if(ch>=0x80 && ch<=0x9F) { - int c=static_cast(*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