Commit a6928a0b by xiongziliang

优化url编解码

parent 119d90bc
...@@ -71,14 +71,14 @@ char StrToBin(const char *str) ...@@ -71,14 +71,14 @@ char StrToBin(const char *str)
string strCoding::UrlEncode(const string &str) { string strCoding::UrlEncode(const string &str) {
string out; string out;
size_t len = str.size(); size_t len = str.size();
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
char ch = str[i]; char ch = str[i];
if (isalnum((uint8_t)ch)) { if (isalnum((uint8_t)ch)) {
out.push_back(ch); out.push_back(ch);
}else { }else {
char tempbuff[4]; char buf[4];
sprintf(tempbuff, "%%%X%X", (uint8_t)str[i] >> 4,(uint8_t)str[i] % 16); sprintf(buf, "%%%X%X", (uint8_t)ch >> 4,(uint8_t)ch & 0x0F);
out.append(tempbuff); out.append(buf);
} }
} }
return out; return out;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论