00001 #pragma once
00002
00003 #include "StringUtilsImpl.h"
00004
00005 namespace AppSecInc
00006 {
00008 namespace StringUtils
00009 {
00017 int replace(std::string& ss, const std::string& from, const std::string& to);
00018 int replace(std::wstring& ss, const std::wstring& from, const std::wstring& to);
00019
00027 void tokenize(const std::string& ss, std::vector<std::string>& tokens, const std::string& delims);
00028 void tokenize(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delims);
00029
00036 std::string join(const std::vector<std::string>& tokens, const std::string& delims);
00037 std::wstring join(const std::vector<std::wstring>& tokens, const std::wstring& delims);
00038 std::string join(const std::list<std::string>& tokens, const std::string& delims);
00039 std::wstring join(const std::list<std::wstring>& tokens, const std::wstring& delims);
00040
00050 void tokenizeWithSkip(const std::string& ss, std::vector<std::string>& tokens, const std::string& delim = " ");
00051 void tokenizeWithSkip(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delim = L" ");
00052
00060 void tokenizeOnChar(const std::string& ss, std::vector<std::string>& tokens, const std::string& delims);
00061 void tokenizeOnChar(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delims);
00062
00068 void ltrim(std::string& ss, const std::string& whitespaces = " \t");
00069 void ltrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
00070
00076 void rtrim(std::string& ss, const std::string& whitespaces = " \t");
00077 void rtrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
00078
00084 void lrtrim(std::string& ss, const std::string& whitespaces = " \t");
00085 void lrtrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
00086
00092 void lrtrimcrlf(std::string& ss, const std::string& whitespaces = " \r\n\t");
00093 void lrtrimcrlf(std::wstring& ss, const std::wstring& whitespaces = L" \r\n\t");
00094
00099 void uppercase(std::string& ss);
00100 void uppercase(std::wstring& ss);
00101
00106 void lowercase(std::string& ss);
00107 void lowercase(std::wstring& ss);
00108
00115 bool comparei(const std::string& ss1, const std::string& ss2);
00116 bool comparei(const std::wstring& ss1, const std::wstring& ss2);
00117
00126 long stringToLong(const std::string& ss, long default_on_error = 0, int base = 10);
00127 long stringToLong(const std::wstring& ss, long default_on_error = 0, int base = 10);
00128 long stringToLong(const char * psz, long default_on_error = 0, int base = 10);
00129 long stringToLong(const wchar_t * psz, long default_on_error = 0, int base = 10);
00130
00136 std::wstring mb2wc(const std::string& from);
00137 std::wstring mb2wc(const char * from);
00138 std::wstring mb2wc(const char * from, unsigned int len);
00139
00145 std::wstring utf82wc(const std::string& from);
00146 std::wstring utf82wc(const char * from);
00147 std::wstring utf82wc(const char * from, unsigned int len);
00148
00154 std::string wc2mb(const std::wstring& from);
00155 std::string wc2mb(const wchar_t * from);
00156 std::string wc2mb(const wchar_t * from, unsigned int len);
00157
00163 std::string wc2utf8(const std::wstring& from);
00164 std::string wc2utf8(const wchar_t * from);
00165 std::string wc2utf8(const wchar_t * from, unsigned int len);
00166
00172 std::string bstr2mb(BSTR from);
00173 std::string bstr2mb(BSTR from, int len);
00174 std::string bstr2mb(const _bstr_t& from);
00175 std::string bstr2mb(const CComBSTR& from);
00176
00182 std::string toString(VARIANT from);
00183 std::string toString(const _variant_t& from);
00184 std::string toString(const CComVariant& from);
00185
00186 std::wstring toWString(VARIANT from);
00187 std::wstring toWString(const _variant_t& from);
00188 std::wstring toWString(const CComVariant& from);
00189
00196 void s2ebcdic(std::string& ss);
00197 void s2ebcdic(unsigned char * s, unsigned long len);
00198
00205 void ebcdic2s(std::string& ss);
00206 void ebcdic2s(unsigned char * s, unsigned long len);
00207
00214 bool startsWith(const std::string& ss, const std::string& what);
00215 bool startsWith(const std::wstring& ss, const std::wstring& what);
00216
00223 bool endsWith(const std::string& ss, const std::string& what);
00224 bool endsWith(const std::wstring& ss, const std::wstring& what);
00225
00227 template<class T>
00228 std::wstring toWString(const T& t)
00229 {
00230 std::wstringstream ss;
00231 ss << t;
00232 return ss.str();
00233 }
00234
00236 template<class T>
00237 std::string toString(const T& t)
00238 {
00239 std::stringstream ss;
00240 ss << t;
00241 return ss.str();
00242 }
00243 }
00244 }