patch for aMule-SVN-r10179
diff -Nur aMule-SVN-r10179/src/libs/common/StringFunctions.cpp aMule-SVN-r10179-ccav2000/src/libs/common/StringFunctions.cpp
--- aMule-SVN-r10179/src/libs/common/StringFunctions.cpp 2010-04-19 04:52:05.000000000 +0800
+++ aMule-SVN-r10179-ccav2000/src/libs/common/StringFunctions.cpp 2010-05-25 11:47:06.542029454 +0800
@@ -109,6 +109,24 @@
return result;
}
+size_t UTF8Len (char byte)
+{
+ if ((byte & 0x80) == 0x0) {
+ return 1;
+ } else if ((byte & 0xE0) == 0xC0) {
+ return 2;
+ } else if ((byte & 0xF0) == 0xE0) {
+ return 3;
+ } else if ((byte & 0xF8) == 0xF0) {
+ return 4;
+ } else if ((byte & 0xFC) == 0xF8) {
+ return 5;
+ } else if ((byte & 0xFE) == 0xFC) {
+ return 6;
+ } else {
+ return 1;
+ }
+}
wxString UnescapeHTML( const wxString& str )
{
@@ -118,15 +136,30 @@
for ( size_t i = 0; i < str.Len(); ++i ) {
if ( str.GetChar(i) == wxT('%') && ( i + 2 < str.Len() ) ) {
wxChar unesc = HexToDec( str.Mid( i + 1, 2 ) );
-
- if ( unesc ) {
- i += 2;
-
- result += unesc;
- } else {
- // If conversion failed, then we just add the escape-code
- // and continue past it like nothing happened.
- result += str.at(i);
+ size_t len;
+ if ((len=UTF8Len(unesc))>1) {
+ if ((i+(len*3)) >= str.Len()) break;
+ unsigned char s[8];
+ memset (s, 0, sizeof(s));
+ s[0] = (unsigned char)unesc;
+ i += 3;
+ for (int j=1; j<len; ++j, i+=3) {
+ unesc = HexToDec (str.Mid(i+1,2));
+ s[j] = (unsigned char)unesc;
+ }
+ result += UTF82unicode ((char*)s);
+ --i;
+ }
+ else {
+ if ( unesc ) {
+ i += 2;
+
+ result += unesc;
+ } else {
+ // If conversion failed, then we just add the escape-code
+ // and continue past it like nothing happened.
+ result += str.at(i);
+ }
}
} else {
result += str.at(i);