} if ( p != end ) { NS_ERROR("Not a UTF-8 string. This code should only be used for converting from known UTF-8 strings."); mErrorEncountered = PR_TRUE; mLength = 0; return N;
while ( state-- ) { c = *p++;  if ( UTF8traits::isInSeq(c) ) { PRInt32 shift = state * 6; ucs4 |= (PRUint32(c) & 0x3F) << shift; } else { NS_ERROR("not a UTF8 string"); mErrorEncountered = PR_TRUE; return N; } }  if ( ucs4 < minUcs4 ) {  *mBuffer++ = UCS2_REPLACEMENT_CHAR; } else if ( ucs4 <= 0xD7FF ) { *mBuffer++ = ucs4; } else if (  ucs4 <= 0xDFFF ) {  *mBuffer++ = UCS2_REPLACEMENT_CHAR; } else if ( ucs4 == 0xFFFE || ucs4 == 0xFFFF ) {  *mBuffer++ = UCS2_REPLACEMENT_CHAR; } else if ( ucs4 >= PLANE1_BASE ) { if ( ucs4 >= 0x00110000 ) *mBuffer++ = UCS2_REPLACEMENT_CHAR; else {  ucs4 -= PLANE1_BASE; *mBuffer++ = (PRUnichar)(ucs4 >> 10) | 0xd800u; *mBuffer++ = (PRUnichar)(ucs4 & 0x3ff) | 0xdc00u; } } else { if ( ucs4 != 0xFEFF ) *mBuffer++ = ucs4; }
    PRUint32 write( const value_type* start, PRUint32 N )      {          // ignore any further requests        if ( mErrorEncountered )            return N;        // algorithm assumes utf8 units won't        // be spread across fragments        const value_type* p = start;        const value_type* end = start + N;        for ( ; p < end /* && *p */; ++mLength )          {            if ( UTF8traits::isASCII(*p) )                p += 1;            else if ( UTF8traits::is2byte(*p) )                p += 2;            else if ( UTF8traits::is3byte(*p) )                p += 3;            else if ( UTF8traits::is4byte(*p) ) {                p += 4;                ++mLength;            }            else if ( UTF8traits::is5byte(*p) )                p += 5;            else if ( UTF8traits::is6byte(*p) )                p += 6;            else              {                break;              }          }        if ( p != end )          {            NS_ERROR("Not a UTF-8 string. This code should only be used for converting from known UTF-8 strings.");            mErrorEncountered = PR_TRUE;            mLength = 0;            return N;          }        return p - start;      }