- if(bytes==0)
- {
- if((*i&0xC0)==0x80)
- {
- error("Invalid UTF-8 string (tail byte when expecting head)");
- ++i;
- break;
- }
- else if(*i&0x80)
- {
- unsigned mask=0x40;
- for(; *i&mask; mask>>=1)
- ++bytes;
-
- if(bytes>3)
- {
- 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
- {
- append(*i++);
- break;
- }
- }
- else
- {
- if((*i&0xC0)!=0x80)
- {
- error("Invalid UTF-8 string (head byte when expecting tail)");
- ++i;
- break;
- }
+ UnicodeChar result=error("UTF-8 tail byte found when expecting head");
+ ++i;
+ return result;
+ }
+ else if(*i&0x80)
+ {
+ unsigned bytes=2;
+ unsigned mask=0x20;
+ for(; *i&mask; mask>>=1)
+ ++bytes;
+
+ string::const_iterator j=i;