WebParser: Fixed that matching failed with Codepage= other than 0 and 65001 in some cases due to r972

This commit is contained in:
Birunthan Mohanathas 2011-10-10 08:20:31 +00:00
parent 2ad2df5252
commit 6820c67a80

View File

@ -94,15 +94,12 @@ std::wstring ConvertToWide(LPCSTR str, int codepage)
if (str && *str) if (str && *str)
{ {
int strLen = (int)strlen(str) + 1; int strLen = (int)strlen(str);
int bufLen = MultiByteToWideChar(codepage, 0, str, strLen, NULL, 0); int bufLen = MultiByteToWideChar(codepage, 0, str, strLen, NULL, 0);
if (bufLen > 0) if (bufLen > 0)
{ {
WCHAR* wideSz = new WCHAR[bufLen]; szWide.resize(bufLen);
wideSz[0] = 0; MultiByteToWideChar(codepage, 0, str, strLen, &szWide[0], bufLen);
MultiByteToWideChar(codepage, 0, str, strLen, wideSz, bufLen);
szWide = wideSz;
delete [] wideSz;
} }
} }
return szWide; return szWide;
@ -114,15 +111,12 @@ std::string ConvertToAscii(LPCWSTR str, int codepage)
if (str && *str) if (str && *str)
{ {
int strLen = (int)wcslen(str) + 1; int strLen = (int)wcslen(str);
int bufLen = WideCharToMultiByte(codepage, 0, str, strLen, NULL, 0, NULL, NULL); int bufLen = WideCharToMultiByte(codepage, 0, str, strLen, NULL, 0, NULL, NULL);
if (bufLen > 0) if (bufLen > 0)
{ {
char* tmpSz = new char[bufLen]; szAscii.resize(bufLen);
tmpSz[0] = 0; WideCharToMultiByte(codepage, 0, str, strLen, &szAscii[0], bufLen, NULL, NULL);
WideCharToMultiByte(codepage, 0, str, strLen, tmpSz, bufLen, NULL, NULL);
szAscii = tmpSz;
delete [] tmpSz;
} }
} }
return szAscii; return szAscii;
@ -874,12 +868,14 @@ void ParseData(UrlData* urlData, LPCSTR parseData, DWORD dwSize)
// Must convert the data to utf8 // Must convert the data to utf8
utf8Data = ConvertWideToUTF8((LPCWSTR)parseData); utf8Data = ConvertWideToUTF8((LPCWSTR)parseData);
parseData = utf8Data.c_str(); parseData = utf8Data.c_str();
dwSize = utf8Data.length();
} }
else if (urlData->codepage != CP_UTF8 && urlData->codepage != 0) // 0 = CP_ACP else if (urlData->codepage != CP_UTF8 && urlData->codepage != 0) // 0 = CP_ACP
{ {
// Must convert the data to utf8 // Must convert the data to utf8
utf8Data = ConvertAsciiToUTF8(parseData, urlData->codepage); utf8Data = ConvertAsciiToUTF8(parseData, urlData->codepage);
parseData = utf8Data.c_str(); parseData = utf8Data.c_str();
dwSize = utf8Data.length();
} }
rc = pcre_exec( rc = pcre_exec(