由于调休所以好长时间没有记录工作博文了,恰巧项目需要,写篇关于URL编解码的纯干货;
直接贴代码:
//************************************
//函数功能:URL编码
//函数名称:URLEncode
//参数说明:const string &sIn:待编码字符串
//返回值 : 编码后的字符串
//其他说明:
//************************************
string URLEncode(const string &sIn)
{
string sOut;
for (size_t ix = 0; ix < sIn.size(); ix++)
{
unsigned char buf[4];
memset(buf, 0, 4);
if (isalnum((unsigned char)sIn[ix]))
{
buf[0] = sIn[ix];
}
else
{
buf[0] = '%';
buf[1] = toHex((unsigned char)sIn[ix] >> 4);
buf[2] = toHex((unsigned char)sIn[ix] % 16);
}
sOut += (char *)buf;
}
return sOut;
};
//************************************
//函数功能:URL解码
//函数名称:URLDecode
//参数说明:const string &sIn:待解码字符串
//返回值 : 解码字符串
//其他说明:
//************************************
string URLDecode(const string &sIn)