COMMON: Added string splitter to StringTokenizer class
This commit is contained in:
parent
135cd721c5
commit
7c59a77aca
2 changed files with 21 additions and 2 deletions
|
@ -52,6 +52,15 @@ String StringTokenizer::nextToken() {
|
|||
return String(_str.c_str() + _tokenBegin, _tokenEnd - _tokenBegin);
|
||||
}
|
||||
|
||||
StringArray StringTokenizer::split() {
|
||||
StringArray res;
|
||||
|
||||
while (!empty())
|
||||
res.push_back(nextToken());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
U32StringTokenizer::U32StringTokenizer(const U32String &str, const String &delimiters) : _str(str), _delimiters(delimiters) {
|
||||
reset();
|
||||
}
|
||||
|
@ -99,5 +108,14 @@ U32String U32StringTokenizer::nextToken() {
|
|||
return U32String();
|
||||
}
|
||||
|
||||
U32StringArray U32StringTokenizer::split() {
|
||||
U32StringArray res;
|
||||
|
||||
while (!empty())
|
||||
res.push_back(nextToken());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#define COMMON_TOKENIZER_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/str.h"
|
||||
#include "common/ustr.h"
|
||||
#include "common/str-array.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
|
@ -55,6 +54,7 @@ public:
|
|||
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)
|
||||
StringArray split(); ///< Returns StringArray with all tokens. Beware of the memory usage
|
||||
|
||||
private:
|
||||
const String _str; ///< The string to be tokenized
|
||||
|
@ -82,6 +82,7 @@ public:
|
|||
void reset(); ///< Resets the tokenizer to its initial state, i.e points boten token iterators to the beginning
|
||||
bool empty() const; ///< Returns true if there are no more tokens left in the string, false otherwise
|
||||
U32String nextToken(); ///< Returns the next token from the string (Or an empty string if there are no more tokens)
|
||||
U32StringArray split(); ///< Returns StringArray with all tokens. Beware of the memory usage
|
||||
|
||||
private:
|
||||
const U32String _str; ///< The unicode string to be tokenized
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue