[xiph-commits] r10027 - trunk/oggdsf/src/lib/helper/libilliCore
davidb at svn.xiph.org
davidb at svn.xiph.org
Fri Sep 16 20:50:54 PDT 2005
Author: davidb
Date: 2005-09-16 20:50:53 -0700 (Fri, 16 Sep 2005)
New Revision: 10027
Modified:
trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.cpp
trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.h
Log:
Handle i18n characters in tags
Modified: trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.cpp
===================================================================
--- trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.cpp 2005-09-17 03:50:19 UTC (rev 10026)
+++ trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.cpp 2005-09-17 03:50:53 UTC (rev 10027)
@@ -40,6 +40,7 @@
{
}
+
wstring StringHelper::toWStr(string inString) {
wstring retVal;
@@ -48,11 +49,106 @@
retVal.append(1, *i);
}
+ return retVal;
+}
+string StringHelper::toUTF8Str(wstring inString) {
+ string retVal;
+
+ unsigned char a;
+ //LPCWSTR retPtr = new wchar_t[retVal.length() + 1];
+ for (std::wstring::const_iterator i = inString.begin(); i != inString.end(); i++)
+ {
+ // 0xxxxxxx
+ if (*i < 0x80)
+ {
+ retVal.append(1, (unsigned char) *i);
+ }
+ // 110xxxxx 10xxxxxx
+ else if (*i < 0x800)
+ {
+ a = (unsigned char)(0xC0 | (unsigned int)*i >> 6);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i & 0x3F);
+ retVal.append(1, a);
+ }
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ else if (*i < 0x10000)
+ {
+ a = (unsigned char)(0xE0 | (unsigned int)*i >> 12);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i >> 6 & 0x3F);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i & 0x3F);
+ retVal.append(1, a);
+ }
+ // 1111xxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ else if (*i < 0x200000)
+ {
+ a = (unsigned char)(0xF0 | (unsigned int)*i >> 18);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i >> 12 & 0x3F);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i >> 6 & 0x3F);
+ retVal.append(1, a);
+ a = (unsigned char)(0x80 | (unsigned int)*i & 0x3F);
+ retVal.append(1, a);
+ }
+ }
+
return retVal;
}
+wstring StringHelper::fromUTF8Str(string inString) {
+ wstring retVal;
+
+ wchar_t a;
+
+ //LPCWSTR retPtr = new wchar_t[retVal.length() + 1];
+ for (int i=0; i < inString.length(); )
+ {
+ // 0xxxxxxx
+ if ((inString[i] & 0x80) == 0)
+ {
+ a = inString[i];
+ i++;
+ }
+ // 1111xxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ else if ((inString[i] & 0xF0) == 0xF0)
+ {
+ a = ((inString[i] & 0x0F) << 18) |
+ ((inString[i+1] & 0x3F) << 12) |
+ ((inString[i+2] & 0x3F) << 6) |
+ (inString[i+3] & 0x3F);
+ i += 3;
+ }
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ else if ((inString[i] & 0xE0) == 0xE0)
+ {
+ a = ((inString[i] & 0x0F) << 12) |
+ ((inString[i+1] & 0x3F) << 6) |
+ (inString[i+2] & 0x3F);
+ i += 3;
+ }
+ // 110xxxxx 10xxxxxx
+ else if ((inString[i] & 0xC0) == 0xC0)
+ {
+ a = ((inString[i] & 0x1F) << 6) | (inString[i+1] & 0x3F);
+ i += 2;
+ }
+ else
+ {
+ // something has gone wrong. Get out!
+ break;
+ }
+
+ retVal.append(1, a);
+ }
+
+ return retVal;
+}
+
string StringHelper::toNarrowStr(wstring inString) {
string retVal;
Modified: trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.h
===================================================================
--- trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.h 2005-09-17 03:50:19 UTC (rev 10026)
+++ trunk/oggdsf/src/lib/helper/libilliCore/StringHelper.h 2005-09-17 03:50:53 UTC (rev 10027)
@@ -66,5 +66,10 @@
/// Converts a wide (2 byte) string to a narrow string.
static string toNarrowStr(wstring inString);
+ /// DLB. 10/9/2005. Converts a wide (2 byte) string to a UTF-8 narrow string.
+ static string toUTF8Str(wstring inString);
+ /// DLB. 10/9/2005. Converts a UTF-8 narrow string to a wide (2 byte) string.
+ static wstring fromUTF8Str(string inString);
+
};
More information about the commits
mailing list