00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "std_ex.h"
00025 #include <sstream>
00026
00027
00028 namespace stdex
00029 {
00030
00031 std::wstring itoa(const int iValue)
00032 {
00033 std::wostringstream sOutStream;
00034 sOutStream << iValue;
00035 return sOutStream.str();
00036 }
00037
00038
00039 std::wstring ltoa(const long lValue)
00040 {
00041 std::wostringstream sOutStream;
00042 sOutStream << lValue;
00043 return sOutStream.str();
00044 }
00045
00046
00047 std::wstring ftoa(const float fValue)
00048 {
00049 std::wostringstream sOutStream;
00050 sOutStream << fValue;
00051 return sOutStream.str();
00052 }
00053
00054
00055 std::wstring dtoa(const double dValue)
00056 {
00057 std::wostringstream sOutStream;
00058 sOutStream << dValue;
00059 return sOutStream.str();
00060 }
00061
00062
00063 int atoi(const std::wstring& sValue)
00064 {
00065 int iResult = 0;
00066 std::wstringstream sTranslation;
00067 sTranslation << sValue;
00068 sTranslation >> iResult;
00069 return iResult;
00070 }
00071
00072
00073 long atol(const std::wstring& sValue)
00074 {
00075 long lResult = 0;
00076 std::wstringstream sTranslation;
00077 sTranslation << sValue;
00078 sTranslation >> lResult;
00079 return lResult;
00080 }
00081
00082
00083 float atof(const std::wstring& sValue)
00084 {
00085 float fResult = 0.0;
00086 std::wstringstream sTranslation;
00087 sTranslation << sValue;
00088 sTranslation >> fResult;
00089 return fResult;
00090 }
00091
00092
00093 double atod(const std::wstring& sValue)
00094 {
00095 double dResult = 0.0;
00096 std::wstringstream sTranslation;
00097 sTranslation << sValue;
00098 sTranslation >> dResult;
00099 return dResult;
00100 }
00101
00102
00103 std::wstring TrimString(const std::wstring& sString)
00104 {
00105 std::wstring::size_type start = sString.find_first_not_of(L" \t");
00106 std::wstring::size_type end = sString.find_last_not_of(L" \t");
00107 std::wstring sResult = L"";
00108 if (start != std::wstring::npos)
00109 {
00110 sResult = sString.substr(start, end - start + 1);
00111 }
00112
00113 return sResult;
00114 }
00115
00116
00117 std::wstring ToWString(const char* sString)
00118 {
00119 size_t iStringLength = std::mbstowcs(0, sString, strlen(sString));
00120 wchar_t* sWString = new wchar_t[iStringLength + 1];
00121 std::mbstowcs(sWString, sString, iStringLength + 1);
00122 std::wstring sOutString(sWString);
00123 delete sWString;
00124 return sOutString;
00125 }
00126
00127
00128 std::string ToMbString(const std::wstring& sWString)
00129 {
00130 size_t iStringLength = std::wcstombs(0, sWString.c_str(), sWString.size() * MB_CUR_MAX);
00131 char* sCharString = new char[iStringLength + 1];
00132 wcstombs(sCharString, sWString.c_str(), iStringLength + 1);
00133 std::string sString(sCharString);
00134 delete sCharString;
00135 return sString;
00136 }
00137
00138
00139 std::vector<std::wstring> DetokenizeString(const std::wstring& sString, const std::wstring& sDelimiters)
00140 {
00141 std::wstring sStringCopy(sString);
00142 std::vector<std::wstring> Tokens;
00143
00144 while (! sStringCopy.empty())
00145 {
00146 std::wstring::size_type DelimiterIndex = sStringCopy.find_first_of(sDelimiters);
00147 if (DelimiterIndex == std::wstring::npos)
00148 {
00149 Tokens.push_back(sStringCopy);
00150 sStringCopy = L"";
00151 }
00152 else
00153 {
00154 Tokens.push_back(sStringCopy.substr(0, DelimiterIndex));
00155 }
00156 sStringCopy = sStringCopy.substr(DelimiterIndex + 1);
00157 }
00158
00159 return Tokens;
00160 }
00161
00162 }