'programming/C_C++'에 해당되는 글 279건

  1. 2011.08.10 URL 인코딩 - URL 디코딩

반응형

URL 인코딩-----------------------------------------------------------------------
void UrlEncode(const char *inStr, char *outStr)
{
int inStrLen;
unsigned short asc;
unsigned char c;
int outIndex=0;
int i=0;

inStrLen = (int)strlen(inStr);
for(i=0; i<inStrLen; i++)
{
c = inStr[i];
asc = c;
if(asc>47 && asc<58 || asc>64 && asc<91 || asc>96 && asc<123)
outStr[outIndex++] = c;
else if(asc==32)
outStr[outIndex++] ='+';
else
{
char temp[4]={0,};
wsprintf(temp,"%%%2x",asc);
if((unsigned short)temp[1] == 32) temp[1]='0';
outStr[outIndex++] = temp[0];
outStr[outIndex++] = temp[1];
outStr[outIndex++] = temp[2];
}
}
outStr[outIndex]=0;
}


URL 디코딩-----------------------------------------------------------------------
void UrlDecode(const char *inStr, char *outStr)
{
int index = 0;
int num = 0;
int retval = 0;

while(*inStr)
{
if(*inStr == '%')
{
int i = 0;
num = 0;
retval = 0;
for (int i = 0; i < 2; i++)
{
*inStr++;
if(*(inStr) < ':')
num = *(inStr) - 48;
else if(*(inStr) > '@'
&& *(inStr) < '[')
num = (*(inStr) - 'A')+10;
else
num = (*(inStr) - 'a')+10;

if((16*(1-i)))
num = (num*16);
retval += num;
}
outStr[index] = retval;
index++;
}
else
{
outStr[index] = *inStr;
index++;
}
*inStr++;
}
}



url : http://smok95.tistory.com/21

반응형
Posted by 공간사랑
,