#define
IsHexNum(c) ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
CString Utf8ToStringT(LPSTR str)
{
_ASSERT(str);
USES_CONVERSION;
WCHAR * buf;
int length = MultiByteToWideChar(CP_UTF8, 0 , str, - 1 , NULL, 0 );
buf = new WCHAR[length + 1 ];
ZeroMemory(buf, (length + 1 ) * sizeof (WCHAR));
MultiByteToWideChar(CP_UTF8, 0 , str, - 1 , buf, length);
return (CString(W2T(buf)));
}
CString UrlDecode(LPCTSTR url)
{
_ASSERT(url);
USES_CONVERSION;
LPSTR _url = T2A(const_cast < LPTSTR > (url));
int i = 0 ;
int length = ( int )strlen(_url);
CHAR * buf = new CHAR[length];
ZeroMemory(buf, length);
LPSTR p = buf;
while (i < length)
{
if (i <= length - 3 && _url[i] == ' % ' && IsHexNum(_url[i + 1 ]) && IsHexNum(_url[i + 2 ]))
{
sscanf(_url + i + 1 , " %x " , p ++ );
i += 3 ;
}
else
{
* (p ++ ) = _url[i ++ ];
}
}
return Utf8ToStringT(buf);
}
CString Utf8ToStringT(LPSTR str)
{
_ASSERT(str);
USES_CONVERSION;
WCHAR * buf;
int length = MultiByteToWideChar(CP_UTF8, 0 , str, - 1 , NULL, 0 );
buf = new WCHAR[length + 1 ];
ZeroMemory(buf, (length + 1 ) * sizeof (WCHAR));
MultiByteToWideChar(CP_UTF8, 0 , str, - 1 , buf, length);
return (CString(W2T(buf)));
}
CString UrlDecode(LPCTSTR url)
{
_ASSERT(url);
USES_CONVERSION;
LPSTR _url = T2A(const_cast < LPTSTR > (url));
int i = 0 ;
int length = ( int )strlen(_url);
CHAR * buf = new CHAR[length];
ZeroMemory(buf, length);
LPSTR p = buf;
while (i < length)
{
if (i <= length - 3 && _url[i] == ' % ' && IsHexNum(_url[i + 1 ]) && IsHexNum(_url[i + 2 ]))
{
sscanf(_url + i + 1 , " %x " , p ++ );
i += 3 ;
}
else
{
* (p ++ ) = _url[i ++ ];
}
}
return Utf8ToStringT(buf);
}