X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstringcodec%2Fiso646fi.cpp;h=0db1d00485df6d553241e27db47fd3176c9fb031;hp=100ce1313f699a441e13b0f88795ef3e192b5dbf;hb=HEAD;hpb=b42ed73a1b241c0e93ee03c43c4584b41c549bac diff --git a/source/stringcodec/iso646fi.cpp b/source/stringcodec/iso646fi.cpp index 100ce13..0db1d00 100644 --- a/source/stringcodec/iso646fi.cpp +++ b/source/stringcodec/iso646fi.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspstrings -Copyright © 2006-2007 Mikko Rasa -Distributed under the LGPL -*/ - #include "codecutils.h" #include "iso646fi.h" @@ -31,40 +24,38 @@ const int mapping[map_size*2]= namespace Msp { -namespace Codecs { +namespace StringCodec { -void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf) +void Iso646Fi::Encoder::encode_char(unichar ch, string &buf) { 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"); + error(ch, buf, invalid_character(ch, "ISO-646-FI")); else buf += tch; } -void Iso646Fi::Encoder::transliterate(UnicodeChar, string &buf) +void Iso646Fi::Encoder::transliterate(unichar, string &buf) { buf += '?'; } -UnicodeChar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i) +unichar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i) { if(i==str.end()) - return error("No input"); + return -1; 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"); + unichar result; + if(ch>=0x80) + result = error(invalid_sequence(i, i+1, "undefined ISO-646-FI character")); else - result = tch; + result = transform_mapping_or_direct(mapping, map_size, ch, true); ++i; return result; } -} // namespace Codecs +} // namespace StringCodec } // namespace Msp