#pragma once #include "stdafx.h" #include #include namespace CCOS_Kernel { class CStringOpt { public: static int GetCharacterSetPageCode(const std::string& strPageCode); static std::wstring StringFormat(const wchar_t *wszformat, ...); static std::string Transformwstring2string(const std::wstring& wstr, unsigned int nCodePage = 0); static std::wstring Transformstring2wstring(const std::string& str, unsigned int nCodePage = 0); static std::string TrimLeft(const std::string & strSource, const std::string& strTrim = " "); static std::string TrimRight(const std::string & strSource, const std::string& strTrim = " "); static std::string Trim(const std::string & strSource, const std::string& strTrim = " "); static std::wstring TrimLeft(const std::wstring & strSource, const std::wstring& strTrim = L" "); static std::wstring TrimRight(const std::wstring & strSource, const std::wstring& strTrim = L" "); static std::wstring Trim(const std::wstring & strSource, const std::wstring& strTrim = L" "); static std::string Replace(const std::string& org, const std::string& keystr, const std::string& replacestr); static std::wstring Replace(const std::wstring& org, const std::wstring &keystr, const std::wstring &replacestr); static bool SplitN(const std::wstring& wstrSource, const std::wstring& wstrSplit, unsigned int nProcessCount, std::vector& vecParams, std::wstring& wstrLeftSource) { vecParams.clear(); if (wstrSource.empty()) { wstrLeftSource = wstrSource; if (nProcessCount == 0) return true; else return false; } if (nProcessCount == 0) { wstrLeftSource = wstrSource; return true; } std::wstring wstrCurrString = wstrSource; for (unsigned int i = 0; i< nProcessCount; i++) { size_t nIndex = wstrCurrString.find(wstrSplit); if(nIndex == std::string::npos) break; vecParams.push_back(wstrCurrString.substr(0, nIndex)); wstrCurrString = wstrCurrString.substr(nIndex + wstrSplit.length()); } if (vecParams.size() == nProcessCount) { wstrLeftSource = wstrCurrString; return true; } else if (vecParams.size() == nProcessCount - 1 && !wstrCurrString.empty()) { vecParams.push_back(wstrCurrString); wstrLeftSource = L""; return true; } else return false; } static void Split(const std::wstring& wstrSource, const std::wstring& wstrSplit, std::vector& vecParams) { vecParams.clear(); if (wstrSource.empty()) return; std::wstring wstrCurrString = wstrSource; while(!wstrCurrString.empty()) { size_t nIndex = wstrCurrString.find(wstrSplit); if (nIndex == std::string::npos) break; vecParams.push_back(wstrCurrString.substr(0, nIndex)); wstrCurrString = wstrCurrString.substr(nIndex + wstrSplit.length()); } if (!wstrCurrString.empty()) vecParams.push_back(wstrCurrString); } static bool HexString2Integer(const std::wstring& wstrSource, int& nResult); static std::string MakeUpper(const std::string & strSource); static std::wstring MakeUpper(const std::wstring & strSource); static std::string MakeLower(const std::string & strSource); static std::wstring MakeLower(const std::wstring & strSource); static bool Hex2Decimal(const std::string & hex_str, int& nDecimal); static bool Hex2Decimal(const std::wstring & hex_str, int& nDecimal); static std::wstring String(unsigned char Value); static std::wstring String(char Value); static std::wstring String(unsigned short Value); static std::wstring String(short Value); static std::wstring String(int nValue); static std::wstring String(unsigned int uValue); static std::wstring String(float fValue); static std::wstring String(double dfValue); static std::wstring String(long long llValue); static std::wstring String(unsigned long long ullValue); }; #define STRINGOPT CCOS_Kernel::CStringOpt #define WS2S(wstr, nCodePage) STRINGOPT::Transformwstring2string(wstr, nCodePage) #define WS2LS(wstr) WS2S(wstr, 0) #define S2WS(str, nCodePage) STRINGOPT::Transformstring2wstring(str, nCodePage) #define LS2WS(str) S2WS(str, 0) #define TOSTRING(value) STRINGOPT::String(value) }