본문 바로가기

Windows/MFC

urlencode

http://www.codeguru.com/cpp/cpp/cpp_mfc/article.php/c4029

[code]
class CURLEncode
{
private:
static CString csUnsafeString;
CString (char num, int radix);
bool isUnsafe(char compareChar);
CString convert(char val);

public:
CURLEncode() { };
virtual ~CURLEncode() { };
CString (CString vData);
};
[/code]


[code]
bool CURLEncode::isUnsafe(char compareChar)
{
bool bcharfound = false;
char tmpsafeChar;
int m_strLen = 0;

m_strLen = csUnsafeString.GetLength();
for(int ichar_pos = 0; ichar_pos < m_strLen ;ichar_pos++)
{
    tmpsafeChar = csUnsafeString.GetAt(ichar_pos);
    if(tmpsafeChar == compareChar)
    {
     bcharfound = true;
     break;
    }
}
int char_ascii_value = 0;
//char_ascii_value = __toascii(compareChar);
char_ascii_value = (int) compareChar;

if(bcharfound == false && char_ascii_value > 32 &&
                             char_ascii_value < 123)
{
    return false;
}
// found no unsafe chars, return false
else
{
    return true;
}

return true;
}

CString CURLEncode::decToHex(char num, int radix)
{
int temp=0;
CString csTmp;
int num_char;

num_char = (int) num;
if (num_char < 0)
    num_char = 256 + num_char;

while (num_char >= radix)
    {
    temp = num_char % radix;
    num_char = (int)floor(num_char / radix);
    csTmp = hexVals[temp];
    }

csTmp += hexVals[num_char];

if(csTmp.GetLength() < 2)
{
    csTmp += '0';
}

CString strdecToHex(csTmp);
// Reverse the String
strdecToHex.MakeReverse();

return strdecToHex;
}

CString CURLEncode::convert(char val)
{
CString csRet;
csRet += "%";
csRet += decToHex(val, 16);
return csRet;
}
[/code]

'Windows > MFC' 카테고리의 다른 글

ezsetup  (0) 2013.10.02
wince 시작프로그램 등록  (0) 2013.10.02
error C2731: 'DllMain'  (0) 2013.10.02
error LNK2001: unresolved external symbol IID_DestNetInternet on Visual  (0) 2013.10.02
InternetGetConnectedState Function  (0) 2013.10.02