url的编解码
来源:互联网 发布:datatype json jsonp 编辑:程序博客网 时间:2024/04/29 13:17
url编码:string ChineseCode::decodeURI(string sIn)
{
string sOut;
for( size_t ix = 0; ix < sIn.size(); ix++ )
{
BYTE ch = 0;
if(sIn[ix]=='%')
{
ch = (fromHex(sIn[ix+1])<<4);
ch |= fromHex(sIn[ix+2]);
ix += 2;
}
else if(sIn[ix] == '+')
{
ch = ' ';
}
else
{
ch = sIn[ix];
}
sOut += (char)ch;
}
return sOut;
}
上边两个方法中用到的子方法:string ChineseCode::encodeURI(string sIn)
{
string sOut;
for( size_t ix = 0; ix < sIn.size(); ix++ )
{
BYTE buf[4];
memset( buf, 0, 4 );
if( isalnum( (BYTE)sIn[ix] ) )
{
buf[0] = sIn[ix];
}
//else if ( isspace( (BYTE)sIn[ix] ) ) //貌似把空格编码成%20或者+都可以
//{
// buf[0] = '+';
//}
else
{
buf[0] = '%';
buf[1] = toHex( (BYTE)sIn[ix] >> 4 );
buf[2] = toHex( (BYTE)sIn[ix] % 16);
}
sOut += (char *)buf;
}
return sOut;
}
inline BYTE ChineseCode::toHex(const BYTE &x)
{
return x > 9 ? x -10 + 'A': x + '0';
}
转载注明下出处:http://fengmm521.blog.163.com/blog/static/25091358201310510471721/inline BYTE ChineseCode::fromHex(const BYTE &x)
{
return isdigit(x) ? x-'0' : x-'A'+10;
}
- url的编解码
- iOS---Url编解码的问题
- js URL编解码的应用说明
- JS中URL参数的编解码
- URL编解码函数
- URL编解码示例
- URL编解码
- URL 编解码
- C++编解码URL
- C++ URL编解码
- URL编解码
- URL编解码
- Url编解码
- URL编解码
- url编解码
- iOS-URL编解码
- url编解码与base64编解码
- VB URL的编解码源码 GB2312 UTF-8编解码
- 使用cocos2d-iphone和cocos2d-x创建帧动画
- 关于python文件操作(转)
- cocos2d-x动画加速与减速(转)
- UTF-8字符串分段选取(转)
- Scala模式匹配
- url的编解码
- IOS中UIScrollView的contentSize、contentOffset和contentInset属性(转)
- 游戏角色中文名生成常用字段
- Java初学者首先下载 JDK 开发环境,然后再下 eclipse(转)
- search
- 正余玄定理
- C语言标准字符串分割
- 牛客网Linux基础分析(知识点记录 11-03)
- 机房收费系统之日、周账单