00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "precomp.h"
00028 #include "CCTChar.h"
00029
00034 std::string MakeAnsiString(const std::tstring& sString)
00035 {
00036 #ifndef _UNICODE
00037
00038 return sString;
00039 #else
00040
00041 int nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, sString.c_str(), (int)sString.size(), NULL, 0, NULL, NULL);
00042 LPSTR pAnsiString = new CHAR[nAnsiChars];
00043 nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, sString.c_str(), (int)sString.size(), pAnsiString, nAnsiChars, NULL, NULL);
00044 std::string sRet(pAnsiString, nAnsiChars);
00045 delete [] pAnsiString;
00046 return sRet;
00047 #endif
00048 }
00049
00054 std::string MakeAnsiString(LPCTSTR pString)
00055 {
00056 #ifndef _UNICODE
00057
00058 return pString;
00059 #else
00060
00061 int nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, pString, -1, NULL, 0, NULL, NULL);
00062 LPSTR pAnsiString = new CHAR[nAnsiChars];
00063 nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, pString, -1, pAnsiString, nAnsiChars, NULL, NULL);
00064 std::string sRet(pAnsiString, nAnsiChars);
00065 delete [] pAnsiString;
00066 return sRet;
00067 #endif
00068 }
00069
00074 std::wstring MakeWideString(const std::tstring& sString)
00075 {
00076 #ifdef _UNICODE
00077
00078 return sString;
00079 #else
00080
00081 int nWideChars = MultiByteToWideChar(CP_ACP, 0, sString.c_str(), sString.size(), NULL, 0);
00082 LPWSTR pWideString = new WCHAR[nWideChars];
00083 nWideChars = MultiByteToWideChar(CP_ACP, 0, sString.c_str(), sString.size(), pWideString, nWideChars);
00084 std::wstring sRet(pWideString, nWideChars);
00085 delete [] pWideString;
00086 return sRet;
00087 #endif
00088 }
00089
00094 std::wstring MakeWideString(LPCTSTR pString)
00095 {
00096 #ifdef _UNICODE
00097
00098 return pString;
00099 #else
00100
00101 int nWideChars = MultiByteToWideChar(CP_ACP, 0, pString, -1, NULL, 0);
00102 LPWSTR pWideString = new WCHAR[nWideChars];
00103 nWideChars = MultiByteToWideChar(CP_ACP, 0, pString, -1, pWideString, nWideChars);
00104 std::wstring sRet(pWideString, nWideChars);
00105 delete [] pWideString;
00106 return sRet;
00107 #endif
00108 }
00109
00114 std::tstring MakeTString(const std::string& sString)
00115 {
00116 #ifdef _UNICODE
00117
00118 int nWideChars = MultiByteToWideChar(CP_ACP, 0, sString.c_str(), (int)sString.size(), NULL, 0);
00119 LPWSTR pWideString = new WCHAR[nWideChars];
00120 nWideChars = MultiByteToWideChar(CP_ACP, 0, sString.c_str(), (int)sString.size(), pWideString, nWideChars);
00121 std::wstring sRet(pWideString, nWideChars);
00122 delete [] pWideString;
00123 return sRet;
00124 #else
00125
00126 return sString;
00127 #endif
00128 }
00129
00134 std::tstring MakeTString(const std::wstring& sString)
00135 {
00136 #ifdef _UNICODE
00137
00138 return sString;
00139 #else
00140
00141 int nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, sString.c_str(), sString.size(), NULL, 0, NULL, NULL);
00142 LPSTR pAnsiString = new CHAR[nAnsiChars];
00143 nAnsiChars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, sString.c_str(), sString.size(), pAnsiString, nAnsiChars, NULL, NULL);
00144 std::string sRet(pAnsiString, nAnsiChars);
00145 delete [] pAnsiString;
00146 return sRet;
00147 #endif
00148 }
00149
00150 std::tstring MakeTStringFromUTF8(const char* pUTF8)
00151 {
00152 int nWideChars = MultiByteToWideChar(CP_UTF8, 0, pUTF8, -1, NULL, 0);
00153 LPWSTR pWideString = new WCHAR[nWideChars];
00154 nWideChars = MultiByteToWideChar(CP_UTF8, 0, pUTF8, -1, pWideString, nWideChars);
00155 std::wstring sRet(pWideString, nWideChars - 1);
00156 delete [] pWideString;
00157 return MakeTString(sRet);
00158 }
00160
00161 std::tstring RemoveHtmlTags (const std::tstring& str)
00162 {
00163 std::tstring ret;
00164
00165 LPCTSTR ptr = str.c_str();
00166 bool ignore = false;
00167 while (*ptr) {
00168 if (*ptr=='<')
00169 ignore = true;
00170 if (!ignore)
00171 ret += *ptr;
00172 if (*ptr == '>')
00173 ignore = false;
00174 ++ptr;
00175 }
00176
00177 return ret;
00178 }