MinitScript  0.9.31 PRE-BETA
UTF8StringTokenizer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
8 
9 using std::string;
10 using std::vector;
11 
12 /**
13  * UTF8 string tokenizer class
14  * @author Andreas Drewke
15  */
17 {
18 
19 private:
20  vector<string> tokens;
21  int idx { 0 };
22 
23 public:
24  /**
25  * Public constructor
26  */
28 
29  /**
30  * Tokenize
31  * @param str string to tokenize
32  * @param delimiters delimiters
33  * @param emptyTokens include empty tokens
34  */
35  void tokenize(const string& str, const string& delimiters, bool emptyTokens = false);
36 
37  /**
38  * @return number of tokens
39  */
40  inline int32_t countTokens() {
41  return tokens.size();
42  }
43 
44  /**
45  * @return has more tokens
46  */
47  inline bool hasMoreTokens() {
48  return idx != tokens.size();
49  }
50 
51  /**
52  * @return next token
53  */
54  inline const string& nextToken() {
55  return tokens[idx++];
56  }
57 
58  /**
59  * @return tokens
60  */
61  inline const vector<string>& getTokens() {
62  return tokens;
63  }
64 
65 };
void tokenize(const string &str, const string &delimiters, bool emptyTokens=false)
Tokenize.