LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
StringUtil.h
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 
30  static std::string ltrim(std::string s)
31  {
32  s.erase(
33  s.begin(),
34  std::find_if(s.begin(), s.end(),
35  std::not1(std::ptr_fun<int, int>(std::isspace))));
36 
37  return s;
38  }
39 
43  static std::string rtrim(std::string s)
44  {
45  s.erase(
46  std::find_if(s.rbegin(), s.rend(),
47  std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
48  s.end());
49 
50  return s;
51  }
52 
57  static std::string Trim(std::string s)
58  {
59  return ltrim(rtrim(s));
60  }
61 
68  static std::vector<std::string> Split(std::string s, char d)
69  {
70  std::vector<std::string> ret;
71 
72  std::string buff;
73 
74  for (UINT32 i = 0; i < s.length(); i++)
75  {
76 
77  if (s.at(i) == d)
78  {
79  ret.push_back(buff);
80  buff.clear();
81  } else
82  {
83  buff.push_back(s.at(i));
84  }
85 
86  }
87  return ret;
88  }
89 
95  template<class T>
96  static std::string ValToString(T val)
97  {
98  std::stringstream ss;
99  ss << std::boolalpha << val;
100 
101  return ss.str();
102  }
103  };
104 
105 }
106 }
107 }
108 
109 #endif