c++之http URL十六进制编码

来源:互联网 发布:网络服务器机柜 编辑:程序博客网 时间:2024/05/12 13:14
std::string gethex( unsigned int c )//参数必须是int,你懂的{std::ostringstream stm ;stm << '%' << std::hex << std::nouppercase << c ;return stm.str();}std::string encode(std::string str){static const std::string unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz""-_.~";std::string r;for( unsigned int i = 0; i<str.length(); i+=1){unsigned char c = str.at(i);//这里必须是无符号型,你懂得if( unreserved.find(c) != -1 ) r += c ; else r += gethex(c) ;}return r;}

0 0