X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fiso646fi.cpp;h=779eadf0d887fa89b30b60b8e33a3669d31cf821;hp=45c29ffb5dab08d1edc80075152af9b12c1b826f;hb=c88a239ff3b218ad0226e8c53356350ccc1f7014;hpb=58384e355b4a78730d69243f1092e47591f2f384 diff --git a/source/iso646fi.cpp b/source/iso646fi.cpp index 45c29ff..779eadf 100644 --- a/source/iso646fi.cpp +++ b/source/iso646fi.cpp @@ -1,63 +1,69 @@ +/* $Id$ + +This file is part of libmspstrings +Copyright © 2006-2007 Mikko Rasa +Distributed under the LGPL +*/ + +#include "codecutils.h" #include "iso646fi.h" using namespace std; +namespace { + +const unsigned map_size=9; + +const int mapping[map_size*2]= +{ + 0xC4, 0x5B, + 0xC5, 0x5D, + 0xD6, 0x5C, + 0xDC, 0x5E, + 0xE4, 0x7B, + 0xE5, 0x7D, + 0xE9, 0x60, + 0xF6, 0x7C, + 0xFC, 0x7E +}; + +} // namespace + namespace Msp { +namespace Codecs { -void Iso646Fi::Encoder::encode_char(wchar_t c) +void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf) { - 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); + int tch=transform_mapping_or_direct(mapping, map_size, ch, false); + if(tch<0 || tch>0x7F) + error(ch, buf, "Can't express character in ISO-646-FI"); else - throw CodecError("Can't express character in ISO-646-FI"); + buf+=tch; } -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()) - return; - - 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); + return error("No input"); + + unsigned char ch=*i; + int tch=(ch<=0x7F ? transform_mapping_or_direct(mapping, map_size, ch, true) : -1); + + UnicodeChar result; + if(tch==-1) + result=error("Undefined ISO-646-FI character"); else - throw CodecError("Invalid ISO-646-FI string (undefined character)"); -} + result=tch; + ++i; + return result; } + +} // namespace Codecs +} // namespace Msp