C++版本的UnEscape 解析\uxxxx\uxxxx编码字符
解析类似于这种Unicode编码格式的字符串
\u5b55\u5987\u88c5\u590f\u88c52018\u65b0\u6b3e\u5bbd\u677e\u77ed\u8896\u4e2d\u957f\u6b3e\u4e0a\u8863\u96ea\u7ebaV\u9886\u8774\u8776\u7ed3\u8fde\u8863\u88d9\u590f\u5b63
当然JavaScript 直接调用unescape就可以解析 自己动手写了一个c++版本的
代码如下:
#define GB2312_ACP 936
std::string UnEscape(const char* strSource)
{
std::string strResult;
int nDestStep = ;
int nLength = strlen(strSource);
if (!nLength || nLength < ) return strResult;
char* pResult = new char[nLength + ];
wchar_t* pWbuufer = nullptr;
if (!pResult)
{
pResult = NULL;
return strResult;
}
ZeroMemory(pResult, nLength + );
for (int nPos = ; nPos < nLength;nPos++)
{
if (strSource[nPos] == '\\' && strSource[nPos+]=='u')
{
char szTemp[];
char szSource[];
ZeroMemory(szTemp, );
ZeroMemory(szSource, );
CopyMemory(szSource, (char*)strSource + nPos +, );
sscanf_s(szSource, "%04X",szTemp);
CopyMemory(pResult + nDestStep, szTemp, );
nDestStep += ;
}
}
nDestStep += ;
pWbuufer = new wchar_t[nDestStep];
if (!pWbuufer)
{
delete[] pWbuufer;
pWbuufer = nullptr;
return strResult;
}
ZeroMemory(pWbuufer, nDestStep);
CopyMemory(pWbuufer, pResult, nDestStep);
delete [] pResult;
pResult = nullptr;
CHAR* MultPtr = nullptr;
int MultLen = -;
//GB2312_ACP = 936
MultLen = ::WideCharToMultiByte(GB2312_ACP, WC_COMPOSITECHECK, pWbuufer, -, NULL, NULL, NULL, NULL);
MultPtr = new CHAR[MultLen + ];
if (MultPtr)
{
ZeroMemory(MultPtr, MultLen + );
::WideCharToMultiByte(GB2312_ACP, WC_COMPOSITECHECK, pWbuufer, -, MultPtr, MultLen, NULL, NULL);
strResult = MultPtr;
delete[] MultPtr;
MultPtr = nullptr;
}
delete [] pWbuufer;
pWbuufer = nullptr;
return strResult;
}
调用方式:
char buf[] = "\\u5b55\\u5987\\u88c5\\u590f\\u88c52018\\u65b0\\u6b3e\\u5bbd\\u677e\\u77ed\\u8896\\u4e2d\\u957f\\u6b3e\\u4e0a\\u8863\\u96ea\\u7ebaV\\u9886\\u8774\\u8776\\u7ed3\\u8fde\\u8863\\u88d9\\u590f\\u5b63";
std::string nLength = UnEscape(buf);
printf("%s\r\n", nLength.c_str());

C++版本的UnEscape 解析\uxxxx\uxxxx编码字符的更多相关文章
- 微信小程序0.11.122100版本新功能解析
微信小程序0.11.122100版本新功能解析 新版本就不再吐槽了,整的自己跟个愤青似的.人老了,喷不动了,把机会留给年轻人吧.下午随着新版本开放,微信居然破天荒的开放了开发者论坛.我很是担心官方 ...
- OpenStack最新版本Folsom架构解析
OpenStack最新版本Folsom架构解析摘要:OpenStack的第6版,版本代号为Folsom的最新版于今年九月底正式发布,Folsom将支持下一代软件定义网络(SDN)作为其核心组成部分.F ...
- 关于新的man版本出现“无法解析 /usr/share/man/zh_CN/man1/ls.1.gz: 没有那个文件或目录“
今天学习了下man,有关详细资料参考:http://www.cnblogs.com/hnrainll/archive/2011/09/06/2168604.html toor@door:/usr/sh ...
- IIS6.0,Apache低版本,PHP CGI 解析漏洞
IIS6.0解析漏洞 在IIS6.0下存在这样的文件"名字.asp;名字.jpg" 代表了jpg文件可以以asp脚本类型的文件执行. 根据这个解析漏洞我们可以上传这种名字类型的图片 ...
- Anrlr4 生成C++版本的语法解析器
一. 写在前面 我最早是在2005年,首次在实际开发中实现语法解析器,当时调研了Yacc&Lex,觉得风格不是太好,关键当时yacc对多线程也支持的不太好,接着就又学习了Bison&F ...
- [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Quartz任务调度(6)schedulerListener分版本超详细解析
schedulerListener 在我们的监听器实现类中,这个类中需实现的方法很多,不需要的可以给出空实现,下面是一些常用的用法: 方法 说明 jobScheduled() Scheduler 在有 ...
- Quartz任务调度(5)TriggerListener分版本超详细解析
TriggerListener 在我们的触发器监听器中,也包含了一系列监听方法 方法 说明 getName() 定义并返回监听器的名字 triggerFired() 当与监听器相关联的 Trigger ...
- Quartz任务调度(4)JobListener分版本超详细解析
JobListener 我们的jobListener实现类必须实现其以下方法: 方法 说明 getName() getName() 方法返回一个字符串用以说明 JobListener 的名称.对于注册 ...
随机推荐
- @codeforces - 1214H@ Tiles Placement
目录 @description@ @solution@ @part - 1@ @part - 2@ @accepted code@ @details@ @description@ 给定一个 n 点的树 ...
- laravel 的路由中间件
简介# Laravel 中间件提供了一种方便的机制来过滤进入应用的HTTP请求.例如,Laravel 内置了一个中间件来验证用户的身份认证 , 如果没有通过身份认证,中间件会将用户重定向到登陆界面,但 ...
- include 语句中使用双引号与括号有什么区别?
Include 的语法 你在学习如何构造函数时,看到了不同的 include 语句: # include <iostream> # include "distance.h&quo ...
- vlc 网页插件的 使用与控制 API
下面开始使用教程: html文档结构: <object class="vlc" type='application/x-vlc-plugin' events='True' w ...
- 解决pip is configured with locations that require TLS/SSL问题
python3.7安装, 解决pip is configured with locations that require TLS/SSL问题1.安装相关依赖 yum install gcc libff ...
- Protobuf c的使用范例
protobuffer (简称PB) 网上的文章一大堆,随便看看,PB使用起来非常方便.这里主要讲讲Protobuf C(简称PC)的使用 1,代码 https://github.com/protob ...
- HDU 4417 Super Mario 主席树查询区间小于某个值的个数
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> ...
- hdu 1045 Fire Net(dfs)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- 2018-2-25-git-rebase-合并多个提交
title author date CreateTime categories git rebase 合并多个提交 lindexi 2018-02-25 11:41:26 +0800 2018-2-1 ...
- ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.You a ...