All pastes #91100 Raw Edit

Someone

public text v1 · immutable
#91100 ·published 2006-07-18 09:21 UTC
rendered paste body
static enum tEncoding
TextEncoding(aTextP)
    unsigned char *aTextP;
{
    int vLength;
    enum tEncoding vEncoding = kAscii7;
    for (; *aTextP; ++aTextP)
    {
        if ((*aTextP & 0xFE) == 0xFC)
            vLength = 5;
        else if ((*aTextP & 0xFC) == 0xF8)
            vLength = 4;
        else if ((*aTextP & 0xF8) == 0xF0)
            vLength = 3;
        else if ((*aTextP & 0xF0) == 0xE0)
            vLength = 2;
        else if ((*aTextP & 0xE0) == 0xC0)
            vLength = 1;
        else if ((*aTextP & 0x80) == 0x00)
            vLength = 0;
        else
            return kLatin1;
        if (vLength > 0)
            vEncoding = kUtf8;
        while (0 < vLength--)
            if ((*++aTextP & 0xC0) != 0x80)
                return kLatin1;
    }
    return vEncoding;
}