码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-01-16 16:41:24      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:c++   url   

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;
}

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

标签:c++   url   

原文地址:http://blog.csdn.net/hellochenlian/article/details/42778759

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!