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;
char c = *p++;  if ( UTF8traits::isASCII(c) ) { *mBuffer++ = buffer_type(c); continue; }  PRUint32 ucs4; PRUint32 minUcs4; PRInt32 state = 0;  if ( UTF8traits::is2byte(c) ) { ucs4 = (PRUint32(c) << 6) & 0x000007C0L; state = 1; minUcs4 = 0x00000080; } else if ( UTF8traits::is3byte(c) ) { ucs4 = (PRUint32(c) << 12) & 0x0000F000L; state = 2; minUcs4 = 0x00000800; } else if ( UTF8traits::is4byte(c) ) { ucs4 = (PRUint32(c) << 18) & 0x001F0000L; state = 3; minUcs4 = 0x00010000; } else if ( UTF8traits::is5byte(c) ) { ucs4 = (PRUint32(c) << 24) & 0x03000000L; state = 4; minUcs4 = 0x00200000; } else if ( UTF8traits::is6byte(c) ) { ucs4 = (PRUint32(c) << 30) & 0x40000000L; state = 5; minUcs4 = 0x04000000; }
    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;      }