- 浏览: 2003384 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (651)
- ACE (35)
- BAT (9)
- C/C++ (116)
- fast-cgi (14)
- COM (27)
- python (59)
- CGI (4)
- C# (2)
- VC (84)
- DataBase (29)
- Linux (96)
- P2P (6)
- PHP (15)
- Web (6)
- Memcached (7)
- IME输入法 (11)
- 设计模式 (2)
- 搜索引擎 (1)
- 个人情感 (4)
- 笔试/面试 (3)
- 一亩三分地 (33)
- 历史 (2)
- 地理 (1)
- 人物 (3)
- 经济 (0)
- 不仅仅是笑哦 (43)
- 小故事大道理 (2)
- http://www.bjdsmyysjk120.com/ (0)
- http://www.bjdsmyy120.com/ (0)
- 它山之石可以攻玉 (15)
- 大学生你关注些什么 (28)
- 数据恢复 (1)
最新评论
-
luokaichuang:
这个规范里还是没有让我明白当浏览器上传文件时,STDIN的消息 ...
FastCGI规范 -
effort_fan:
好文章!学习了,谢谢分享!
com技术简介 -
vcell:
有错误os.walk(strPath)返回的已经是全部的文件和 ...
通过python获取目录的大小 -
feifeigd:
feifeigd 写道注意:文章中的CPP示例第二行 #inc ...
ATL入门:利用ATL编写简单的COM组件 -
feifeigd:
注意:文章中的CPP示例第二行 #include " ...
ATL入门:利用ATL编写简单的COM组件
#include "stdafx.h" #include <string> using namespace std; unsigned int utf8_decode( char *s, unsigned int *pi ) { unsigned int c; int i = *pi; /* one digit utf-8 */ if ((s[i] & 128)== 0 ) { c = (unsigned int) s[i]; i += 1; } else if ((s[i] & 224)== 192 ) { /* 110xxxxx & 111xxxxx == 110xxxxx */ c = (( (unsigned int) s[i] & 31 ) << 6) + ( (unsigned int) s[i+1] & 63 ); i += 2; } else if ((s[i] & 240)== 224 ) { /* 1110xxxx & 1111xxxx == 1110xxxx */ c = ( ( (unsigned int) s[i] & 15 ) << 12 ) + ( ( (unsigned int) s[i+1] & 63 ) << 6 ) + ( (unsigned int) s[i+2] & 63 ); i += 3; } else if ((s[i] & 248)== 240 ) { /* 11110xxx & 11111xxx == 11110xxx */ c = ( ( (unsigned int) s[i] & 7 ) << 18 ) + ( ( (unsigned int) s[i+1] & 63 ) << 12 ) + ( ( (unsigned int) s[i+2] & 63 ) << 6 ) + ( (unsigned int) s[i+3] & 63 ); i+= 4; } else if ((s[i] & 252)== 248 ) { /* 111110xx & 111111xx == 111110xx */ c = ( ( (unsigned int) s[i] & 3 ) << 24 ) + ( ( (unsigned int) s[i+1] & 63 ) << 18 ) + ( ( (unsigned int) s[i+2] & 63 ) << 12 ) + ( ( (unsigned int) s[i+3] & 63 ) << 6 ) + ( (unsigned int) s[i+4] & 63 ); i += 5; } else if ((s[i] & 254)== 252 ) { /* 1111110x & 1111111x == 1111110x */ c = ( ( (unsigned int) s[i] & 1 ) << 30 ) + ( ( (unsigned int) s[i+1] & 63 ) << 24 ) + ( ( (unsigned int) s[i+2] & 63 ) << 18 ) + ( ( (unsigned int) s[i+3] & 63 ) << 12 ) + ( ( (unsigned int) s[i+4] & 63 ) << 6 ) + ( (unsigned int) s[i+5] & 63 ); i += 6; } else { c = '?'; i++; } *pi = i; return c; } std::string UrlEncode(const std::string& src) { static char hex[] = "0123456789ABCDEF"; std::string dst; for (size_t i = 0; i < src.size(); i++) { unsigned char ch = src[i]; if (isalnum(ch)) { dst += ch; } else if (src[i] == ' ') { dst += '+'; } else { unsigned char c = static_cast<unsigned char>(src[i]); dst += '%'; dst += hex[c / 16]; dst += hex[c % 16]; } } return dst; } std::string UrlDecode(const std::string& src) { std::string dst, dsturl; int srclen = src.size(); for (size_t i = 0; i < srclen; i++) { if (src[i] == '%') { if(isxdigit(src[i + 1]) && isxdigit(src[i + 2])) { char c1 = src[++i]; char c2 = src[++i]; c1 = c1 - 48 - ((c1 >= 'A') ? 7 : 0) - ((c1 >= 'a') ? 32 : 0); c2 = c2 - 48 - ((c2 >= 'A') ? 7 : 0) - ((c2 >= 'a') ? 32 : 0); dst += (unsigned char)(c1 * 16 + c2); } } else if (src[i] == '+') { dst += ' '; } else { dst += src[i]; } } int len = dst.size(); for(unsigned int pos = 0; pos < len;) { unsigned int nvalue = utf8_decode((char *)dst.c_str(), &pos); dsturl += (unsigned char)nvalue; } return dsturl; } // 测试程序 int main(int argc, char* argv[]) { string str1 = "VC知识库 vckbase.com"; string str2 = "www.vckbase.com/sql.asp?id=2%20update and sele%%ct%fc%80%80%80%80%af"; printf("%s ", UrlEncode(str1).c_str()); // URL编码 printf("%s ", UrlDecode(str2).c_str()); // URL解码 return 0; }
发表评论
-
Berkeley DB 使用经验总结
2012-08-27 14:41 3033作者:陈磊 NoSQL是现在互联网Web2.0时代备受 ... -
嵌入式数据库系统Berkeley DB
2012-08-27 14:37 1481前言 UNIX/LINUX平台下的数据库种类非常多 ... -
C语言中标准输入流、标准输出流、标准错误输出流
2011-06-13 14:32 9207C语言中标准输入流、标准输出流、标准错误输出流 在 ... -
Rsync 实现原理
2011-05-12 20:06 8257Rsync 实现原理 前言 关于rsync的原始文档 ... -
c++简单的虚函数测试
2011-04-27 14:25 970#include <iostream> u ... -
C++文件行查找
2011-04-26 14:10 1357#include <iostream> # ... -
c++偏特化简单示例
2011-04-13 11:17 2111c++偏特化 // temp1.c ... -
GDB调试精粹及使用实例
2011-03-16 14:06 1089GDB调试精粹及使用实例 一:列文件清单 1. ... -
简单的ini文件解析
2011-02-12 16:36 1578int GetKeyVal(const string s ... -
scanf族函数高级用法
2011-01-25 16:00 2491如何解释 fscanf(fd,&quo ... -
使用scons替代makefile(1)
2011-01-25 11:58 3643早在多年前我刚开始接触linux下的C程序时,经常被makef ... -
使用scons替代makefile(2)
2011-01-25 11:57 3536本篇文章接着上一篇进一步介绍scons的使用方法,主要介绍静态 ... -
使用scons替代makefile(3)
2011-01-25 11:55 4777在上两篇文章中已经简单介绍了用scons编译库文件,可执行程序 ... -
C 支持动态添加测试数据的测试代码
2011-01-13 17:22 1082/下面的定义为了支持可扩增。 //当需要增加一个新的测试用列 ... -
Linux下Makefile的automake生成
2010-12-28 16:55 1051******************helloworld.c* ... -
SCons笔记(详细版)
2010-12-23 16:11 103871. 基本使用 SConstruct文件就功能而言相当于Ma ... -
scons 学习
2010-12-23 11:14 2115scons 学习 作者:Sam(甄峰) sam_code@h ... -
scons随笔
2010-12-22 20:20 4644scons随笔 Scons是新一代的软件构件工具,或者说ma ... -
Scons在linux下的安装和使用
2010-12-21 11:59 3206因为正在用的一个开源软件需要的Developm ... -
排列组合的实现
2010-12-20 12:41 1014简单算法: 从前往后(或者从后往前)每次交换一个位置。当存在 ...
相关推荐
C++的UrlEncode UrlDecode代码。
NULL 博文链接:https://icecream0.iteye.com/blog/854682
网址编码解码,jQuery版Url.encode,Url.decode,Url.parse,一个来自jQuery的URL Decoder解码、编码插件,为你的URL安全定义一道安全防线,示例文件本身就是一个值得学习的实例,自带的示例将告诉你如何使用这款URL...
Encode_ Decode Tools URL编码解码工具
Oracle秘密 编码/解码《塞尔达传说》,《 Oracle历代传说》和《 Oracle四季》的机密。 安装 $ npm install --save oracle-secret 用法 加载一个GameSecret import { GameSecret } from 'oracle-secret' ;...
小巧实用,支持ANSI和UTF-8编码和译码,web编程必备.
自己写的,可能有bug,请大家一块学习 环境为PB12 函数(及参数) 作用 arraysort 对一维数组进行排序 ...urldecode 将指定字符串以进行指定字符集url解码 urlencode 将指定字符串以进行指定字符集url编码 涨价了,哈哈
urlencode urldecode实现,在xcode里使用c++混编
NULL 博文链接:https://lindows.iteye.com/blog/259125
主要给大家介绍了关于java中URLEncoder.encode与URLDecoder.decode处理url特殊参数的方法,文中介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
包括(UrlEncode、UrlDecode、HtmlEncode、HtmlDecode),html文件,直接在浏览器操作,可查看源码
UrlEncodeUrlDecodeUrl解码Url编码工具 基于UrlEncode,UrlDecode的解码编码工具,支持双向。
如果不想在url中看到有明文,比如http://localhost:8080/template_1/login.action?user=张三 可以使用js的encodeURI的URLDecoder.decode一起使用一起来把url加密下 (1)JS在页面上把数据var val = encodeURI...
即: 如果有空格就用 代替,如果有其它字符就用%ASCII...具体实现如下: 代码如下:function urldecode(encodestr) newstr=”” havechar=false lastchar=”” for i=1 to len(encodestr) char_c=mid(encode
用于解码已编码的URL的漂亮工具。 ...在您编码了URL并且实际上想要读取它时,有用! 使用此实用程序解码(或编码)URL。 URL编码(也称为百分比 - 编码)是用于在统一资源标识符(URI)中的信息编码信息的机制。 这...
一个极好的工具,用于解码已经编码的url。当你已经编码了一个URL并且实际上想要读它时,它是有用的! 使用此实用程序解码(或编码)URL。 URL编码(也称为百分比编码)是一种用于在统一资源标识符(URI)中对信息进行...
网络传输文本,urlEncode和decode的实现。 在vs 2005上通过实验。
将Url进行编码,前台JS需要使用这段内容,这时候就需要解码了: 代码 代码如下: /** * Url编码 **/ ShengUtils.encode = function(unzipStr){ var zipstr=””; var strSpecial=”!\”#$%&'()*+,/:;<=>?[]^`{|}~%”...
常用的SQL,及SQL优化
本文用C++来实现UrlEncode!