123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #pragma once
- #include "stdafx.h"
- #include <string>
- #include <vector>
- 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<std::wstring>& 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<std::wstring>& 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)
- }
|