My Project
StringHelper.h
1 #pragma once
2 #include <string>
3 #include <map>
4 #include <float.h>
5 using namespace std;
6 
7 namespace ParaEngine
8 {
13  {
14  public:
30  static bool UTF8ToUTF16(const std::string& utf8, std::u16string& outUtf16);
32  static bool UTF8ToUTF16_Safe(const std::string& utf8, std::u16string& outUtf16);
33 
34  /*
35  * @str: the string to trim
36  * @index: the index to start trimming from.
37  *
38  * Trims str st str=[0, index) after the operation.
39  *
40  * Return value: the trimmed string.
41  * */
42  static void TrimUTF16VectorFromIndex(std::vector<char16_t>& str, int index);
43 
44  /*
45  * @ch is the unicode character whitespace?
46  *
47  * Reference: http://en.wikipedia.org/wiki/Whitespace_character#Unicode
48  *
49  * Return value: weather the character is a whitespace character.
50  * */
51  static bool IsUnicodeSpace(char16_t ch);
52 
53  static bool IsCJKUnicode(char16_t ch);
54 
55  static void TrimUTF16Vector(std::vector<char16_t>& str);
56 
57 
58  /*
59  * @str: the string to search through.
60  * @c: the character to not look for.
61  *
62  * Return value: the index of the last character that is not c.
63  * */
64  static unsigned int GetIndexOfLastNotChar16(const std::vector<char16_t>& str, char16_t c);
65 
81  static bool UTF16ToUTF8(const std::u16string& utf16, std::string& outUtf8);
82 
83  static const WCHAR* MultiByteToWideChar(const char* name, unsigned int nCodePage = 0, size_t* outLen = nullptr);
84  static const char* WideCharToMultiByte(const WCHAR* name, unsigned int nCodePage = 0, size_t* outLen = nullptr);
91  static int WideCharToMultiByte(const WCHAR* name, char* szText, int nLength, unsigned int nCodePage = 0);
92 
93  static const WCHAR* AnsiToWideChar(const char* name);
94  static const char* WideCharToAnsi(const WCHAR* name);
95 
96  static const char* UTF8ToAnsi(const char* name);
97  static const char* AnsiToUTF8(const char* name);
98 
101  static int GetUnicodeCharNum(const char* str);
102 
109  static string UniSubString(const char* str, int nFrom, int nTo);
110 
115  static string SimpleEncode(const string& source);
116 
121  static string SimpleDecode(const string& source);
122 
140  static const std::string& EncodingConvert(const std::string& srcEncoding, const std::string& dstEncoding, const std::string& bytes);
141 
143  static bool CopyTextToClipboard(const string& text);
144 
146  static const char* GetTextFromClipboard();
147 
149  static void DevideString(const string& input,string& str1,string&str2,char separator=';');
150 
152  static void split(const std::string& src, const std::string& token, std::vector<std::string>& vect);
153 
155  static void make_lower(string& str);
156 
158  static void make_upper(string& str);
159 
165  static bool checkValidXMLChars( const std::string& data );
166 
172  static bool removeInValidXMLChars( std::string& data );
173 
174  static bool IsNumber(const char * str);
175  static bool IsLetter(const char * str);
176  static int StrToInt(const char *str);
177  static double StrToFloat(const char * str);
178  static bool RegularMatch(const char *input,const char *expression);
179  //replace all "\" in a string to "\\"
180  static std::string ToCString(const char* input);
181  static std::string StrReplace(const char* inputstring, char srcchar,char destchar);
182  static RECT * GetImageAndRect(const std::string &str,std::string &imagefile, RECT * pOut=NULL);
183 
187  static std::string md5(const std::string& source, bool bBinary = false);
188 
189  /*
190  convert the sha1 of the input source string.
191  * @param bBinary: if false (default), result is 32 hex number chars. if true, result is 16 bytes binary string.
192  */
193  static std::string sha1(const std::string& source, bool bBinary = false);
194 
196  static std::string base64(const std::string& source);
198  static std::string unbase64(const std::string& source);
199 
200 
201 
207  static void fast_sprintf(char* s,const char *fmt, ...);
208  static void fast_snprintf(char* s, int nMaxCount, const char *fmt, ...);
209 
217  static int fast_itoa( int64 value, char* result, int buf_size, int base = 10 );
218 
228  static int fast_dtoa(double num, char* str, int nBuffSize=40, int max_decimal=5, int radix = 10);
229 
233  static bool MatchWildcard(const std::string& str, const std::string& sWildcardPattern);
234 
238  static bool StrEndsWith(const string& str, const string& sequence);
239 
240 
241  private:
242  class _CodePageName
243  {
244  public:
245  _CodePageName()
246  {
247 #ifdef WIN32
248  auto cp = GetACP();
249  char tmp[30];
250  ParaEngine::StringHelper::fast_itoa((int)cp, tmp, 30);
251 
252  name = "CP";
253  name += tmp;
254 #else
255  name = "utf-8";
256 #endif
257  }
258 
259  const std::string& get() const
260  {
261  return name;
262  }
263 
264  private:
265  std::string name;
266 
267  };
268 
269  static _CodePageName defaultCPName;
270 
271  };
272 }
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ManagedDef.h:18
string manipulation helpers for ParaEngine
Definition: StringHelper.h:12
Definition: enum_maker.hpp:46
static int fast_itoa(int64 value, char *result, int buf_size, int base=10)
fast itoa modified from http://code.google.com/p/maxmods/
Definition: StringHelper.cpp:1213