LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
StringUtil.hpp
1 #ifndef RHESUS_STRINGUTIL_H_
2 #define RHESUS_STRINGUTIL_H_
3 
4 #include <string>
5 #include <sstream>
6 #include <vector>
7 #include <algorithm>
8 #include <functional>
9 #include <cctype>
10 #include <locale>
11 
12 namespace Rhesus
13 {
14 namespace Toolkit
15 {
16 namespace Utilities
17 {
18 
19  /*
20  * @brief Contains functions to perform string operations
21  * @author Varun Parthasarathy
22  */
23  class StringUtil
24  {
25  public:
26  static std::string ltrim(std::string s)
27  {
28  s.erase(
29  s.begin(),
30  std::find_if(s.begin(), s.end(),
31  std::not1(std::ptr_fun<int, int>(std::isspace))));
32 
33  return s;
34  }
35 
36  // trim from end
37  static std::string rtrim(std::string s)
38  {
39  s.erase(
40  std::find_if(s.rbegin(), s.rend(),
41  std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
42  s.end());
43 
44  return s;
45  }
46 
47  // trim from both ends
48  static std::string Trim(std::string s)
49  {
50  return ltrim(rtrim(s));
51  }
52 
53  static std::vector<std::string> Split(std::string s, char d)
54  {
55  std::vector<std::string> ret;
56 
57  std::string buff;
58 
59  for (UINT32 i = 0; i < s.length(); i++)
60  {
61 
62  if (s.at(i) == d)
63  {
64  ret.push_back(buff);
65  buff.clear();
66  } else
67  {
68  buff.push_back(s.at(i));
69  }
70 
71  }
72  return ret;
73  }
74 
75  template<class T>
76  static std::string ValToString(T val)
77  {
78  std::stringstream ss;
79  ss << std::boolalpha << val;
80 
81  return ss.str();
82  }
83  };
84 
85 }
86 }
87 }
88 
89 #endif