00001
00003
00023 #ifndef _STRTOK_H_
00024 #define _STRTOK_H_
00025
00026
00027 #include <string>
00028
00029 typedef std::string::size_type SIZE;
00030
00032
00054 class StringTokenizer
00055 {
00056 public:
00058
00066 StringTokenizer(const std::string& rStr, char cDelim = ',', char cPrefix = '\0');
00067
00069 ~StringTokenizer() {}
00070
00072
00075 inline bool HasMoreTokens() const
00076 {
00077 return m_pos < m_len;
00078 }
00079
00081
00091 std::string GetNextToken(bool fSkipEmpty = false);
00092
00094
00103 std::string GetNextTokenRaw(bool fSkipEmpty = false);
00104
00106
00116 std::string GetRemainder();
00117
00119
00128 inline void SetDelimiter(char cDelim)
00129 {
00130 m_cDelim = cDelim;
00131 }
00132
00134
00137 inline char GetDelimiter() const
00138 {
00139 return m_cDelim;
00140 }
00141
00143
00151 inline void SetPrefix(char cPrefix)
00152 {
00153 m_cPrefix = cPrefix;
00154 }
00155
00157
00160 inline char GetPrefix() const
00161 {
00162 return m_cPrefix;
00163 }
00164
00166
00171 inline void SetNoPrefix()
00172 {
00173 SetPrefix('\0');
00174 }
00175
00177
00180 inline void Reset()
00181 {
00182 m_pos = 0;
00183 }
00184
00185 private:
00186 std::string m_str;
00187 char m_cDelim;
00188 char m_cPrefix;
00189 std::string::size_type m_pos;
00190 std::string::size_type m_len;
00191
00193
00198 std::string StripPrefix(const char* s, SIZE cnt);
00199
00201
00207 void _GetNextToken(std::string& rToken, bool fStripPrefix);
00208
00210
00217 void _GetNextTokenNoPrefix(std::string& rToken);
00218
00220
00227 void _GetNextTokenWithPrefix(std::string& rToken);
00228 };
00229
00230
00231 #endif //_STRTOK_H_