Пример #1
0
UCS2String UTF8toUCS2String(const UTF8String& s)
{
    UCS2String result;
    UCS4 c;
    int len = 0;

    // Compute the encoded length by simply counting all non-continuation bytes.
    // In case of malformed sequences we might get the number wrong, but this is just an estimate
    // used to pre-allocate memory.
    for (UTF8String::const_iterator i = s.begin(); i != s.end(); ++i)
        if (((*i) & 0xC0) != 0x80)
            ++len;

    result.reserve(len);

    for(UTF8String::const_iterator i = s.begin(); i != s.end(); )
    {
        c = DecodeUTF8Character(i);

        if ((c > 0xFFFFu) || (c == 0x0000u))
            // Not valid in UCS2, or we can't deal with it; substitute with a replacement character.
            c = 0xFFFDu;

        result.push_back(c);
    }

    return result;
}
Пример #2
0
UTF8String Filename::getExtension(bool includeDot) const
{
	const UTF8String fname = getFilename();
	UTF8String::const_reverse_iterator it = std::find(fname.rbegin(), fname.rend(), '.');
	if (it!=fname.rend())
		return UTF8String(it.base() - ((includeDot) ? 1 : 0), fname.end());
	else
		return UTF8String("");
}