namespace Msp {
-void Iso2022Jp::Encoder::encode_char(wchar_t c)
+void Iso2022Jp::Encoder::encode_char(wchar_t c_)
{
+ // Win32 has typedef unsigned short wchar_t
+ int c=c_;
+
if(c>=0 && c<=0x7F && c!=0x5C && c!=0x7E)
{
if(mode!=ASCII && mode!=JISX0201)
{
unsigned short jis=ucs_to_jisx0208(c);
if(!jis)
- throw CodecError("Can't express character in ISO-2022-JP");
- if(mode!=JISX0208)
- switch_mode(JISX0208);
+ error("Can't express character in ISO-2022-JP");
+ else
+ {
+ if(mode!=JISX0208)
+ switch_mode(JISX0208);
- char buf[2]={jis>>8, jis};
- append(buf, 2);
+ char buf[2]={jis>>8, jis};
+ append(buf, 2);
+ }
}
}
}
}
-Iso2022Jp::Decoder::Decoder():
+void Iso2022Jp::Encoder::append_replacement()
+{
+ if(mode!=ASCII)
+ switch_mode(ASCII);
+ append(032);
+}
+
+Iso2022Jp::Decoder::Decoder(ErrorMode em):
+ StringCodec::Decoder(em),
mode(ASCII),
dec(new Ascii::Decoder),
escape(0)
case 0x1B284A: switch_mode(JISX0201); break; // ESC ( J
case 0x1B2440: // ESC $ @
case 0x1B2442: switch_mode(JISX0208); break; // ESC $ B
- default: throw CodecError("Invalid ISO-2022-JP escape sequence");
+ default: error("Invalid ISO-2022-JP escape sequence");
}
escape=0;
}
void Iso2022Jp::Decoder::sync()
{
if(escape)
- throw CodecError("Sync in middle of ISO-2022-JP escape sequence");
+ {
+ error("Sync in middle of ISO-2022-JP escape sequence");
+ escape=0;
+ }
+
if(mode!=ASCII)
- throw CodecError("Sync while not in ASCII mode");
- append(dec->get());
- dec->flush();
-}
-
-void Iso2022Jp::Decoder::reset()
-{
- switch_mode(ASCII);
- escape=0;
+ {
+ error("Sync while not in ASCII mode");
+ switch_mode(ASCII);
+ }
+ else
+ {
+ append(dec->get());
+ dec->flush();
+ }
}
void Iso2022Jp::Decoder::switch_mode(Mode m)