diff options
Diffstat (limited to 'common/util.h')
-rw-r--r-- | common/util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/util.h b/common/util.h index 8e5fd8d1ed..e7a71ff42c 100644 --- a/common/util.h +++ b/common/util.h @@ -75,6 +75,32 @@ namespace Common { bool matchString(const char *str, const char *pat); /** + * A simple non-optimized string tokenizer. + * + * Example of use: + * StringTokenizer("Now, this is a test!", " ,!") gives tokens "Now", "this", "is", "a" and "test" using nextToken(). + */ +class StringTokenizer { +public: + /** + * Creates a StringTokenizer. + * @param str The string to be tokenized. + * @param delimiters String containing all the delimiter characters (i.e. the characters to be ignored). + * @note Uses space, horizontal tab, carriage return, newline, form feed and vertical tab as delimiters by default. + */ + StringTokenizer(const String &str, const String &delimiters = " \t\r\n\f\v"); + void reset(); //!< Resets the tokenizer to its initial state + bool empty() const; //!< Returns true if there are no more tokens left in the string, false otherwise + String nextToken(); //!< Returns the next token from the string (Or an empty string if there are no more tokens) + +private: + const String _str; //!< The string to be tokenized + const String _delimiters; //!< String containing all the delimiter characters + uint _tokenBegin; //!< Latest found token's begin (Valid after a call to nextToken(), zero otherwise) + uint _tokenEnd; //!< Latest found token's end (Valid after a call to nextToken(), zero otherwise) +}; + +/** * Print a hexdump of the data passed in. The number of bytes per line is * customizable. * @param data the data to be dumped |