C++中实现类似php的UTF8和UrlEncode函数

C++中实现类似php的UTF8和UrlEncode函数,第1张

概述C++中实现类似php的UTF8和UrlEncode函数

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

#include <string>#include <vector>  inline BYTE toHex(const BYTE x){    return x>9?x+55:x+48;}  std::string WC2UT(const wchar_t* buf){    int len=WIDeCharToMultiByte(CP_UTF8,buf,-1,NulL,NulL);    std::vector<char> utf8(len);    WIDeCharToMultiByte(CP_UTF8,&utf8[0],len,NulL);    return std::string(&utf8[0]);}  std::wstring MB2WC(const char* buf){    int len=MultiBytetoWIDeChar(CP_ACP,0);    std::vector<wchar_t> unicode(len);    MultiBytetoWIDeChar(CP_ACP,&unicode[0],len);    return std::wstring(&unicode[0]);}  //参数要用指针。voID URLEncode(CString* str){    std::string sln=str->GetBuffer(0);    sln=WC2UT(MB2WC(sln.c_str()).c_str());    std::string sOut;    for (size_t ix=0;ix<sln.size();ix++)    {        BYTE buf[4];        memset(buf,4);        if (isalnum((BYTE)sln[ix]))            buf[0]=sln[ix];        else if (isspace((BYTE)sln[ix]))            buf[0]='+';        else        {            buf[0]='%';            buf[1]=toHex((BYTE)sln[ix]>>4);            buf[2]=toHex((BYTE)sln[ix]);        }        sOut+=(char*)buf;    }    CString out=sOut.c_str();    *str=out;}

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的C++中实现类似php的UTF8和UrlEncode函数全部内容,希望文章能够帮你解决C++中实现类似php的UTF8和UrlEncode函数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232151.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存