Beispiel #1
0
void String::SetUTF8FromWChar(const wchar_t* str)
{
    char temp[7];

    Clear();

    if (!str)
        return;

#ifdef _WIN32
    while (*str)
    {
        unsigned unicodeChar = DecodeUTF16(str);
        char* dest = temp;
        EncodeUTF8(dest, unicodeChar);
        *dest = 0;
        Append(temp);
    }
#else
    while (*str)
    {
        char* dest = temp;
        EncodeUTF8(dest, (unsigned)*str++);
        *dest = 0;
        Append(temp);
    }
#endif
}
	//----------------------------------------------------------------------------
	int GetTextLength(const char *text)
	{
		if (mEncoding == UTF16)
		{
			int textLen = 0;
			for (;;)
			{
				unsigned int len;
				int r = DecodeUTF16((const unsigned char *)&text[textLen], &len);
				if (r > 0)
				{
					textLen += len;
				}
				else if (r < 0)
				{
					textLen++;
				}
				else
					return textLen;
			}
		}

		// Both UTF8 and standard ASCII strings can use strlen
		return (int)strlen(text);
	}
Beispiel #3
0
static int Font_GetTextLength ( const char *text )
{
	EFontTextEncoding encoding = cur_pFont->encoding;
	int textLen = 0;

	if ( encoding == UTF16 )
	{
		for ( ;; )
		{
			unsigned int len;
			int r = DecodeUTF16 ( &text[textLen], &len );

			if ( r > 0 )
				textLen += len;
			else if ( r < 0 )
				textLen++;
			else
				return textLen;
		}
	}

	return strlen ( text );
}
	//----------------------------------------------------------------------------
	int GetTextChar(const char *text, int pos, int *nextPos=0)
	{
		int ch;
		unsigned int len;
		if (mEncoding == UTF8)
		{
			ch = DecodeUTF8((const unsigned char *)&text[pos], &len);
			if (ch == -1) len = 1;
		}
		else if (mEncoding == UTF16)
		{
			ch = DecodeUTF16((const unsigned char *)&text[pos], &len);
			if (ch == -1) len = 2;
		}
		else
		{
			len = 1;
			ch = (unsigned char)text[pos];
		}

		if (nextPos) *nextPos = pos + len;
		return ch;
	}
Beispiel #5
0
static int Font_GetTextChar ( const char *text, int pos, int *nextPos )
{
	int ch;
	unsigned int len;
	EFontTextEncoding encoding = cur_pFont->encoding;

	if ( encoding == UTF8 )
	{
		ch = DecodeUTF8 ( &text[pos], &len );

		if ( ch == -1 ) len = 1;
	}
	else if ( encoding == UTF16 )
	{
		ch = DecodeUTF16 ( &text[pos], &len );

		if ( ch == -1 ) len = 2;
	}
	else
	{
		len = 1;
		ch = ( unsigned char ) text[pos];

		if ( ch >= 0x80 ) //oem
		{
			U16 oemcode;
			int ch2 = ( unsigned char ) text[pos + 1];
			len = 2;
			oemcode = ( ( U16 ) ch << 8 ) + ch2;
			ch = oem_to_unicode ( oemcode ); //oem to unicode
		}
	}

	if ( nextPos ) *nextPos = pos + len;

	return ch;
}