删除重复代码

This commit is contained in:
xiongziliang 2019-05-27 12:13:27 +08:00
parent c857968f40
commit 3e54018409
4 changed files with 6 additions and 58 deletions

View File

@ -53,7 +53,7 @@ public:
for(auto &pr : *this){
ret.append(pr.first);
ret.append("=");
ret.append(strCoding::UrlUTF8Encode(pr.second));
ret.append(strCoding::UrlEncode(pr.second));
ret.append("&");
}
if(ret.size()){

View File

@ -590,7 +590,7 @@ inline HttpSession::KeyValue HttpSession::makeHttpHeader(bool bClose, int64_t iC
}
string HttpSession::urlDecode(const string &str){
auto ret = strCoding::UrlUTF8Decode(str);
auto ret = strCoding::UrlDecode(str);
#ifdef _WIN32
GET_CONFIG_AND_REGISTER(string,charSet,Http::kCharSet);
bool isGb2312 = !strcasecmp(charSet.data(), "gb2312");

View File

@ -68,7 +68,7 @@ char StrToBin(const char *str)
return chn;
}
string strCoding::UrlUTF8Encode(const string &str) {
string strCoding::UrlEncode(const string &str) {
string dd;
size_t len = str.size();
for (size_t i = 0; i < len; i++) {
@ -88,7 +88,7 @@ string strCoding::UrlUTF8Encode(const string &str) {
}
return dd;
}
string strCoding::UrlUTF8Decode(const string &str) {
string strCoding::UrlDecode(const string &str) {
string output = "";
char tmp[2];
int i = 0, len = str.length();
@ -111,55 +111,6 @@ string strCoding::UrlUTF8Decode(const string &str) {
return output;
}
string strCoding::UrlGB2312Encode(const string &str)
{
string dd;
size_t len = str.size();
for (size_t i = 0; i<len; i++)
{
if (isalnum((uint8_t)str[i]))
{
char tempbuff[2];
sprintf(tempbuff, "%c", str[i]);
dd.append(tempbuff);
}
else if (isspace((uint8_t)str[i]))
{
dd.append("+");
}
else
{
char tempbuff[4];
sprintf(tempbuff, "%%%X%X", (uint8_t)str[i] >> 4, (uint8_t)str[i] % 16);
dd.append(tempbuff);
}
}
return dd;
}
string strCoding::UrlGB2312Decode(const string &str)
{
string output = "";
char tmp[2];
int i = 0, idx = 0, len = str.length();
while (i<len) {
if (str[i] == '%') {
tmp[0] = str[i + 1];
tmp[1] = str[i + 2];
output += StrToBin(tmp);
i = i + 3;
}
else if (str[i] == '+') {
output += ' ';
i++;
}
else {
output += str[i];
i++;
}
}
return output;
}
///////////////////////////////windows专用///////////////////////////////////
#if defined(_WIN32)

View File

@ -36,11 +36,8 @@ namespace mediakit {
class strCoding {
public:
static string UrlUTF8Encode(const string &str); //urlutf8 编码
static string UrlUTF8Decode(const string &str); //urlutf8解码
static string UrlGB2312Encode(const string &str); //urlgb2312编码
static string UrlGB2312Decode(const string &str); //urlgb2312解码
static string UrlEncode(const string &str); //urlutf8 编码
static string UrlDecode(const string &str); //urlutf8解码
#if defined(_WIN32)
static string UTF8ToGB2312(const string &str);//utf_8转为gb2312
static string GB2312ToUTF8(const string &str); //gb2312 转utf_8