Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
StringTokenizer.h
Go to the documentation of this file.
1 #ifndef STRINGTOKENIZER_H
2 #define STRINGTOKENIZER_H
3 
4 #include <algorithm>
5 #include <functional>
6 #include <cctype>
7 #include <locale>
8 #include <string>
9 #include <sstream>
10 #include <cstdio>
11 
12 #include "Types.h"
13 
15 {
16 public:
17  tcStringTokenizer(std::string ahToTokenize, char ahDelimeter = ' ');
18 
23  bool hasNext();
24 
29  std::string next();
30 
37  bool nextIntHex(int32 *apRet);
38 
45  bool nextUIntHex(uint32 *apRet);
46 
47 
54  bool nextInt(int32 *apRet);
55 
62  bool nextUnsigned(uint32 *apRet);
63 
70  bool nextDouble(double *apRet);
71 
78  bool nextFloat(float *apRet);
79 
87  bool nextBool(bool *apRet);
88 
89 private:
90  char mhDelimeter;
91  std::string mhToTokenize;
92  std::istringstream mhStringStream;
93 
94  // trim from start
95  static inline std::string &ltrim(std::string &s)
96  {
97  size_t num_spaces = 0;
98  while ((num_spaces < s.size()) && std::isspace(s.at(num_spaces))) {
99  ++num_spaces;
100  }
101  s.erase(0,num_spaces);
102  return s;
103  }
104 
105  // trim from end
106  static inline std::string &rtrim(std::string &s)
107  {
108  if (!s.empty()) {
109  size_t num_spaces = 0;
110  size_t index = s.size() - 1;
111  while ((index > 0) && (num_spaces < s.size()) && std::isspace(s.at(index))) {
112  ++num_spaces;
113  --index;
114  }
115  s.erase(index + 1, std::string::npos);
116  }
117  return s;
118  }
119 
120  // trim from both ends
121  static inline std::string &trim(std::string &s)
122  {
123  return ltrim(rtrim(s));
124  }
125 
126 };
127 
128 #endif // STRINGTOKENIZER_H
tcStringTokenizer::nextUIntHex
bool nextUIntHex(uint32 *apRet)
Definition: StringTokenizer.cpp:45
int32
int32_t int32
Definition: Types.h:8
tcStringTokenizer::nextFloat
bool nextFloat(float *apRet)
Definition: StringTokenizer.cpp:108
tcStringTokenizer::nextDouble
bool nextDouble(double *apRet)
Definition: StringTokenizer.cpp:92
Types.h
tcStringTokenizer::nextIntHex
bool nextIntHex(int32 *apRet)
Definition: StringTokenizer.cpp:29
tcStringTokenizer::tcStringTokenizer
tcStringTokenizer(std::string ahToTokenize, char ahDelimeter=' ')
Definition: StringTokenizer.cpp:4
tcStringTokenizer::nextUnsigned
bool nextUnsigned(uint32 *apRet)
Definition: StringTokenizer.cpp:76
tcStringTokenizer::hasNext
bool hasNext()
Definition: StringTokenizer.cpp:13
tcStringTokenizer
Definition: StringTokenizer.h:14
uint32
uint32_t uint32
Definition: Types.h:11
tcStringTokenizer::nextInt
bool nextInt(int32 *apRet)
Definition: StringTokenizer.cpp:60
tcStringTokenizer::next
std::string next()
Definition: StringTokenizer.cpp:18
tcStringTokenizer::nextBool
bool nextBool(bool *apRet)
Definition: StringTokenizer.cpp:124