+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
#include "utf8.h"
using namespace std;
{
unsigned code=c;
if(code>0x10FFFF)
- throw CodecError("Can't express character in UTF-8");
+ {
+ error("Can't express character in UTF-8");
+ return;
+ }
unsigned bytes=1;
if(code>0xFFFF)
if(bytes==0)
{
if((*i&0xC0)==0x80)
- throw CodecError("Invalid UTF-8 string (tail byte when expecting head)");
-
+ {
+ error("Invalid UTF-8 string (tail byte when expecting head)");
+ ++i;
+ break;
+ }
else if(*i&0x80)
{
unsigned mask=0x40;
++bytes;
if(bytes>3)
- throw CodecError("Invalid UTF-8 string (overlong multibyte sequence)");
-
- code=(*i++)&(mask-1);
- if(!code)
- throw CodecError("Invalid UTF-8 string (denormalized multibyte sequence)");
+ {
+ error("Invalid UTF-8 string (overlong multibyte sequence)");
+ ++i;
+ break;
+ }
+ else
+ {
+ code=(*i++)&(mask-1);
+ if(!code)
+ {
+ error("Invalid UTF-8 string (denormalized multibyte sequence)");
+ break;
+ }
+ }
}
else
{
else
{
if((*i&0xC0)!=0x80)
- throw CodecError("Invalid UTF-8 string (head byte when expecting tail)");
+ {
+ error("Invalid UTF-8 string (head byte when expecting tail)");
+ ++i;
+ break;
+ }
code=code<<6 | (*i++)&0x3F;
--bytes;
if(!bytes)
{
if(code>0x10FFFF)
- throw CodecError("Invalid UTF-8 string (character out of range)");
- append(code);
+ error("Invalid UTF-8 string (character out of range)");
+ else
+ append(code);
break;
}
}
void Utf8::Decoder::sync()
{
if(bytes)
- throw CodecError("Sync in the middle of multibyte UTF-8 sequence");
+ {
+ error("Sync in the middle of multibyte UTF-8 sequence");
+ bytes=0;
+ }
+}
+
+void Utf8::Decoder::reset()
+{
+ bytes=0;
}
} // namespace Msp