博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php函数UrlEncode的C++版
阅读量:5140 次
发布时间:2019-06-13

本文共 1376 字,大约阅读时间需要 4 分钟。

CString s2utfs(const wstring& strSrc){string strRes;wstring wstrUni = strSrc;char* chUTF8 = new char[wstrUni.length() * 3];memset(chUTF8,0x00,wstrUni.length() * 3);CString strName = Uni2UTF(wstrUni,chUTF8, wstrUni.length() * 3);strRes = chUTF8; delete []chUTF8;return strName;}CString URLEncode( const wstring& strRes, char *utf8, int nMaxSize ){if (utf8 == NULL) {return L"";}CString strName;int len = 0;int size_d = nMaxSize;for (wstring::const_iterator it = strRes.begin(); it != strRes.end(); ++it){wchar_t wchar = *it;if (wchar < 0x80){
strName += wchar;continue;}else if(wchar < 0x800){
if (len + 1 >= size_d)return L"";utf8[len++] = 0xc0 | ( wchar >> 6 );utf8[len++] = 0x80 | ( wchar & 0x3f );}else if(wchar < 0x10000 ){
if (len + 2 >= size_d)return L"";utf8[len++] = 0xe0 | ( wchar >> 12 );utf8[len++] = 0x80 | ( (wchar >> 6) & 0x3f );utf8[len++] = 0x80 | ( wchar & 0x3f );}else if( wchar < 0x200000 ) {
if (len + 3 >= size_d)return L"";utf8[len++] = 0xf0 | ( (int)wchar >> 18 );utf8[len++] = 0x80 | ( (wchar >> 12) & 0x3f );utf8[len++] = 0x80 | ( (wchar >> 6) & 0x3f );utf8[len++] = 0x80 | ( wchar & 0x3f );}char *q = new char[40];char *p = utf8;for (int i = 0;i < 3;i++){char *q = new char[40];sprintf(q,"%x",*p++);strName += "%";strName += q;}len = 0;}strName.Replace(L"ffffff",L"");return strName;}

 

转载于:https://www.cnblogs.com/nonine/p/3182444.html

你可能感兴趣的文章
JavaSE基础之 IO流
查看>>
DDoS攻防战 (一) : 概述
查看>>
根据现有PDF模板填充信息(SpringBoot)
查看>>
div+css布局的好处
查看>>
《需求工程——软件建模与分析》阅读笔记一
查看>>
如何成为一枚好测试员
查看>>
【Nowcoder】玩游戏
查看>>
过滤器(Filter)
查看>>
字符串的操作
查看>>
性能优化之Java(Android)代码优化
查看>>
springMVC相关—文件上传
查看>>
由Oracle 11g SYSAUX 和 SYSTEM 表空间回收引发的联想
查看>>
uva 1416 Warfare And Logistics
查看>>
欲则不达
查看>>
盒子游戏
查看>>
OpenJudgeP1.10.08:病人排队__(刷题)_水题
查看>>
观察者模式
查看>>
Hadoop分布式文件系统中架构和设计要点汇总
查看>>
cout和printf
查看>>
UVa 10088 - Trees on My Island (pick定理)
查看>>