-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
-Distributed under the LGPL
-*/
#include "ascii.h"
#include "iso2022jp.h"
#include "jisx0201.h"
using namespace std;
namespace Msp {
-namespace Codecs {
+namespace StringCodec {
-void Iso2022Jp::Encoder::encode_char(UnicodeChar ch, string &buf)
+void Iso2022Jp::Encoder::encode_char(unichar ch, string &buf)
{
if(ch>=0 && ch<=0x7F && ch!=0x5C && ch!=0x7E)
{
{
Kuten jis = ucs_to_jisx0208(ch);
if(!jis)
- return error(ch, buf, "Can't express character in ISO-2022-JP");
+ return error(ch, buf, invalid_character(ch, "ISO-2022-JP"));
if(mode!=JISX0208)
switch_mode(JISX0208, buf);
- char jbuf[2] = {jis.ku+0x20, jis.ten+0x20};
+ char jbuf[2] = { jis.ku+0x20, jis.ten+0x20 };
buf.append(jbuf, 2);
}
}
case ASCII: buf.append("\033(B", 3); break;
case JISX0201: buf.append("\033(J", 3); break;
case JISX0208: buf.append("\033$B", 3); break;
- default: throw CodecError("WTF? Invalid mode in Iso2022Jp::Encoder::switch_mode");
+ default: throw invalid_argument("Iso2022Jp::Encoder::switch_mode");
}
}
-void Iso2022Jp::Encoder::transliterate(UnicodeChar, string &buf)
+void Iso2022Jp::Encoder::transliterate(unichar, string &buf)
{
if(mode!=ASCII)
switch_mode(ASCII, buf);
dec(new Ascii::Decoder)
{ }
-UnicodeChar Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterator &i)
+unichar Iso2022Jp::Decoder::decode_char(const string &str, string::const_iterator &i)
{
if(i==str.end())
- return error("No input");
+ return -1;
while(i!=str.end())
{
string::const_iterator j = i;
- UnicodeChar result = -1;
+ unichar result = -1;
if(*j==033)
{
unsigned escape = 0;
else if(dec)
return dec->decode_char(str, i);
else
- throw CodecError("WTF? No sub-decoder for Iso2022Jp::Decoder");
+ throw logic_error("no sub-decoder");
if(result>=0)
return result;
}
}
-} // namespace Codecs
+} // namespace StringCodec
} // namespace Msp