Subversion Repositories public

Rev

Rev 45 | Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45 Rev 47
Line 24... Line 24...
24
#define _STRTOK_H_
24
#define _STRTOK_H_
25
25
26
26
27
#include <string>
27
#include <string>
28
28
-
 
29
/// Simple string tokenizer class.
-
 
30
/**
-
 
31
 * This class implements a string tokenizer. It splits a string
-
 
32
 * by a character to a number of elements (tokens) which are
-
 
33
 * provided sequentially.
29
34
 *
-
 
35
 * All operations are made on the original string itself.
-
 
36
 * The implementation is not ready to handle any changes of the
-
 
37
 * string.
-
 
38
 *
-
 
39
 * The original string is left unchanged. All tokens are returned
-
 
40
 * as newly created strings.
-
 
41
 */
30
class StringTokenizer
42
class StringTokenizer
31
{
43
{
32
public:
44
public:
-
 
45
  /// Constructor.
-
 
46
  /**
-
 
47
   * Creates a ready-to-use tokenizer.
-
 
48
   *
-
 
49
   * \param[in] rStr string for tokenizing
-
 
50
   * \param[in] cDelim delimiter (separator) character
-
 
51
   */
33
  StringTokenizer(const std::string& rStr, char cDelim = ',');
52
  StringTokenizer(const std::string& rStr, char cDelim = ',');
34
 
53
 
-
 
54
  /// Destructor.
35
  ~StringTokenizer() {}
55
  ~StringTokenizer() {}
36
 
56
 
-
 
57
  /// Checks whether the tokenizer can provide more tokens.
-
 
58
  /**
-
 
59
   * \return true = more tokens available, false = otherwise
-
 
60
   */
37
  inline bool HasMoreTokens() const
61
  inline bool HasMoreTokens() const
38
  {
62
  {
39
    return m_pos < m_len;
63
    return m_pos < m_len;
40
  }
64
  }
41
 
65
 
-
 
66
  /// Returns the next token.
-
 
67
  /**
-
 
68
   * \return next token or "" if no more tokens available
-
 
69
   */
42
  std::string GetNextToken();
70
  std::string GetNextToken();
43
 
71
 
-
 
72
  /// Sets a delimiter (separator) character.
-
 
73
  /**
-
 
74
   * The new delimiter has effect only to tokens returned later;
-
 
75
   * the position in the string is not affected.
-
 
76
   *
-
 
77
   * \param[in] cDelim delimiter character
-
 
78
   */
44
  inline void SetDelimiter(char cDelim)
79
  inline void SetDelimiter(char cDelim)
45
  {
80
  {
46
    m_cDelim = cDelim;
81
    m_cDelim = cDelim;
47
  }
82
  }
48
 
83
 
-
 
84
  /// Returns the delimiter (separator) character.
-
 
85
  /**
-
 
86
   * \return delimiter character
-
 
87
   */
49
  inline char GetDelimiter() const
88
  inline char GetDelimiter() const
50
  {
89
  {
51
    return m_cDelim;
90
    return m_cDelim;
52
  }
91
  }
53
 
92
 
-
 
93
  /// Resets the tokenizer.
-
 
94
  /**
-
 
95
   * Re-initializes tokenizing to the start of the string.
-
 
96
   */
54
  inline void Reset()
97
  inline void Reset()
55
  {
98
  {
56
    m_pos = 0;
99
    m_pos = 0;
57
  }
100
  }
58
 
101
 
59
private:
102
private:
60
  std::string m_str;
103
  std::string m_str;            ///< tokenized string
61
  char m_cDelim;
104
  char m_cDelim;                ///< delimiter character
62
  std::string::size_type m_pos;
105
  std::string::size_type m_pos; ///< current position
63
  std::string::size_type m_len;
106
  std::string::size_type m_len; ///< string length
64
};
107
};
65
108
66
109
67
#endif //_STRTOK_H_
110
#endif //_STRTOK_H_