ChineseCode class
2016-12-24 13:19
381 查看
// ChineseCode.cpp: implementation of the ChineseCode class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ChineseCode.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// void ChineseCode::UTF_8ToUnicode(wchar_t* pOut,char *pText) { char* uchar = (char *)pOut; uchar[1] = ((pText[0] & 0x0F) << 4) + ((pText[1] >> 2) & 0x0F); uchar[0] = ((pText[1] & 0x03) << 6) + (pText[2] & 0x3F); return; } void ChineseCode::UnicodeToUTF_8(char* pOut,wchar_t* pText) { // 注意 WCHAR高低字的顺序,低字节在前,高字节在后 char* pchar = (char *)pText; pOut[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4)); pOut[1] = (0x80 | ((pchar[1] & 0x0F) << 2)) + ((pchar[0] & 0xC0) >> 6); pOut[2] = (0x80 | (pchar[0] & 0x3F)); return; } void ChineseCode::UnicodeToGB2312(char* pOut,wchar_t uData) { WideCharToMultiByte(CP_ACP,NULL,&uData,1,pOut,sizeof(wchar_t),NULL,NULL); return; } void ChineseCode::Gb2312ToUnicode(wchar_t* pOut,char *gbBuffer) { ::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,gbBuffer,2,pOut,1); return ; } void ChineseCode::GB2312ToUTF_8(string& pOut,char *pText, int pLen) { char buf[4]; int nLength = pLen* 3; char* rst = new char[nLength]; memset(buf,0,4); memset(rst,0,nLength); int i = 0; int j = 0; while(i < pLen) { //如果是英文直接复制就可以 if( *(pText + i) >= 0) { rst[j++] = pText[i++]; } else { wchar_t pbuffer; Gb2312ToUnicode(&pbuffer,pText+i); UnicodeToUTF_8(buf,&pbuffer); unsigned short int tmp = 0; tmp = rst[j] = buf[0]; tmp = rst[j+1] = buf[1]; tmp = rst[j+2] = buf[2]; j += 3; i += 2; } } rst[j] = '\0'; //返回结果 pOut = rst; delete []rst; return; } void ChineseCode::UTF_8ToGB2312(string &pOut, char *pText, int pLen) { char * newBuf = new char[pLen]; char Ctemp[4]; memset(Ctemp,0,4); int i =0; int j = 0; while(i < pLen) { if(pText[i] > 0) { newBuf[j++] = pText[i++]; } else { WCHAR Wtemp; UTF_8ToUnicode(&Wtemp,pText + i); UnicodeToGB2312(Ctemp,Wtemp); newBuf[j] = Ctemp[0]; newBuf[j + 1] = Ctemp[1]; i += 3; j += 2; } } newBuf[j] = '\0'; pOut = newBuf; delete []newBuf; return; }
相关文章推荐
- [DFNews] US students get cracking on Chinese malware code
- CProxyDllMaker : a class to make proxy dll's masm source code
- Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingExc
- 获得执行jar的运行路径-使用java.class.path 和 codesource的location
- Code snippet of the day : Get Chinese Spell in C#
- 错误 java.lang.ClassFormatError: Invalid method Code length 的解决办法
- Replace Type Code with Class(以类取代型别码)
- Bytecode Visualizer 一个好用的class字节码查看工具
- spark scala code demo for def class etc.
- unresolved external symbol "private: static class std::codecvt问题的解决
- C++ UTF8编码转换 CChineseCode
- Codeforces Round #378 (Div. 2) E. Sleep in Class (思考,双指针,模拟)
- Decompiled .class file,bytecode version:51.0(Java 7) Source for 'Android API 23 Platform' not found
- Base64 Encode/Decode Class C++ SourceCode - Base64编码/解码 类 C++ 源码
- 关于android编程中遇到的Could not find class 'com.swetake.util.Qrcode错误的原因及解决办法
- IDEA查看源码时提示:Library source does not match the bytecode for class的问题分析
- dedeCMS /data/mysql_error_trace.php DB error raised PHP Code Injection Via /include/dedesql.class.php Log FIle Without Access Validation
- view class source code with JAD plugin in Eclipse
- 8.13 replace type code with class(以类取代类型码)
- java source code reverse class diagram of uml,tool