StringUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "StringUtilsImpl.h"
4 
5 namespace AppSecInc
6 {
8  namespace StringUtils
9  {
17  int replace(std::string& ss, const std::string& from, const std::string& to);
18  int replace(std::wstring& ss, const std::wstring& from, const std::wstring& to);
19 
27  void tokenize(const std::string& ss, std::vector<std::string>& tokens, const std::string& delims);
28  void tokenize(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delims);
29 
36  std::string join(const std::vector<std::string>& tokens, const std::string& delims);
37  std::wstring join(const std::vector<std::wstring>& tokens, const std::wstring& delims);
38  std::string join(const std::list<std::string>& tokens, const std::string& delims);
39  std::wstring join(const std::list<std::wstring>& tokens, const std::wstring& delims);
40 
50  void tokenizeWithSkip(const std::string& ss, std::vector<std::string>& tokens, const std::string& delim = " ");
51  void tokenizeWithSkip(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delim = L" ");
52 
60  void tokenizeOnChar(const std::string& ss, std::vector<std::string>& tokens, const std::string& delims);
61  void tokenizeOnChar(const std::wstring& ss, std::vector<std::wstring>& tokens, const std::wstring& delims);
62 
68  void ltrim(std::string& ss, const std::string& whitespaces = " \t");
69  void ltrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
70 
76  void rtrim(std::string& ss, const std::string& whitespaces = " \t");
77  void rtrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
78 
84  void lrtrim(std::string& ss, const std::string& whitespaces = " \t");
85  void lrtrim(std::wstring& ss, const std::wstring& whitespaces = L" \t");
86 
92  void lrtrimcrlf(std::string& ss, const std::string& whitespaces = " \r\n\t");
93  void lrtrimcrlf(std::wstring& ss, const std::wstring& whitespaces = L" \r\n\t");
94 
99  void uppercase(std::string& ss);
100  void uppercase(std::wstring& ss);
101 
106  void lowercase(std::string& ss);
107  void lowercase(std::wstring& ss);
108 
115  bool comparei(const std::string& ss1, const std::string& ss2);
116  bool comparei(const std::wstring& ss1, const std::wstring& ss2);
117 
126  long stringToLong(const std::string& ss, long default_on_error = 0, int base = 10);
127  long stringToLong(const std::wstring& ss, long default_on_error = 0, int base = 10);
128  long stringToLong(const char * psz, long default_on_error = 0, int base = 10);
129  long stringToLong(const wchar_t * psz, long default_on_error = 0, int base = 10);
130 
136  std::wstring mb2wc(const std::string& from);
137  std::wstring mb2wc(const char * from);
138  std::wstring mb2wc(const char * from, unsigned int len);
139 
145  std::wstring utf82wc(const std::string& from);
146  std::wstring utf82wc(const char * from);
147  std::wstring utf82wc(const char * from, unsigned int len);
148 
154  std::string wc2mb(const std::wstring& from);
155  std::string wc2mb(const wchar_t * from);
156  std::string wc2mb(const wchar_t * from, unsigned int len);
157 
163  std::string wc2utf8(const std::wstring& from);
164  std::string wc2utf8(const wchar_t * from);
165  std::string wc2utf8(const wchar_t * from, unsigned int len);
166 
172  std::string bstr2mb(BSTR from);
173  std::string bstr2mb(BSTR from, int len);
174  std::string bstr2mb(const _bstr_t& from);
175  std::string bstr2mb(const CComBSTR& from);
176 
182  std::string toString(VARIANT from);
183  std::string toString(const _variant_t& from);
184  std::string toString(const CComVariant& from);
185 
186  std::wstring toWString(VARIANT from);
187  std::wstring toWString(const _variant_t& from);
188  std::wstring toWString(const CComVariant& from);
189 
196  void s2ebcdic(std::string& ss);
197  void s2ebcdic(unsigned char * s, unsigned long len);
198 
205  void ebcdic2s(std::string& ss);
206  void ebcdic2s(unsigned char * s, unsigned long len);
207 
214  bool startsWith(const std::string& ss, const std::string& what);
215  bool startsWith(const std::wstring& ss, const std::wstring& what);
216 
223  bool endsWith(const std::string& ss, const std::string& what);
224  bool endsWith(const std::wstring& ss, const std::wstring& what);
225 
227  template<class T>
228  std::wstring toWString(const T& t)
229  {
230  std::wstringstream ss;
231  ss << t;
232  return ss.str();
233  }
234 
236  template<class T>
237  std::string toString(const T& t)
238  {
239  std::stringstream ss;
240  ss << t;
241  return ss.str();
242  }
243  }
244 }
void lrtrim(std::string &ss, const std::string &whitespaces=" \t")
Definition: StringUtils.cpp:84
void tokenizeOnChar(const std::string &ss, std::vector< std::string > &tokens, const std::string &delims)
Definition: StringUtils.cpp:54
bool startsWith(const std::string &ss, const std::string &what)
Definition: StringUtils.cpp:134
std::string join(const std::vector< std::string > &tokens, const std::string &delims)
Definition: StringUtils.cpp:24
bool endsWith(const std::string &ss, const std::string &what)
Definition: StringUtils.cpp:144
int replace(std::string &ss, const std::string &from, const std::string &to)
Definition: StringUtils.cpp:4
void tokenize(const std::string &ss, std::vector< std::string > &tokens, const std::string &delims)
Definition: StringUtils.cpp:14
std::string bstr2mb(BSTR from)
Definition: StringUtils.cpp:324
void ebcdic2s(std::string &ss)
Definition: StringUtils.cpp:534
std::wstring toWString(VARIANT from)
Definition: StringUtils.cpp:364
std::string toString(VARIANT from)
Definition: StringUtils.cpp:359
std::wstring utf82wc(const std::string &from)
Definition: StringUtils.cpp:213
std::wstring mb2wc(const std::string &from)
Definition: StringUtils.cpp:154
void lowercase(std::string &ss)
Definition: StringUtils.cpp:114
long stringToLong(const std::string &ss, long default_on_error=0, int base=10)
Definition: StringUtils.cpp:270
std::string wc2mb(const std::wstring &from)
Definition: StringUtils.cpp:184
bool comparei(const std::string &ss1, const std::string &ss2)
Definition: StringUtils.cpp:124
std::string wc2utf8(const std::wstring &from)
Definition: StringUtils.cpp:242
void rtrim(std::string &ss, const std::string &whitespaces=" \t")
Definition: StringUtils.cpp:74
void s2ebcdic(std::string &ss)
Definition: StringUtils.cpp:529
void ltrim(std::string &ss, const std::string &whitespaces=" \t")
Definition: StringUtils.cpp:64
void tokenizeWithSkip(const std::string &ss, std::vector< std::string > &tokens, const std::string &delim=" ")
Definition: StringUtils.cpp:44
void lrtrimcrlf(std::string &ss, const std::string &whitespaces=" \r\n\t")
Definition: StringUtils.cpp:94
void uppercase(std::string &ss)
Definition: StringUtils.cpp:104


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com