My Project
 All Classes Namespaces Functions Pages
stokenize.h
1 #ifndef STOKENIZE_H
2 #define STOKENIZE_H
3 
4 #include <iostream>
5 #include <vector>
6 #include <map>
7 #include <string>
8 
9 #include "token.h"
10 
11 using namespace std;
12 
13 class STokenize
14 {
15  private:
16  string mBlock; // a whole "hello, there. Please tokenize me! and, yeah "
17  unsigned int mPos;
18  map<TokenType, string> mTokenDictionary; // this is a replacement for mCharList
19 
20  // Helper functions
21  void constructDictionary();
22  TokenType getTokenType(const char& ch);//check what token is ch
23 
24  public:
25  STokenize();// by default, construct dictionary for
26  STokenize(const string s);
27  friend STokenize& operator >> (STokenize& t, string& token);
28 
29  void setBlock(const string &block);
30  const string& getBlock();
31 
32  void reset(); // reset mPos
33  bool More(); //check if there is more token to extract
34  bool Fail(); //unkown, !More() ?
35  Token nextToken(); // Get next token in a mBlock
36  vector<Token> getTokens();
37 
38  // Static Functions to operate with external datas
39  static void capitalize(string& s);
40 
41  ~STokenize(); // destroy none, no dynamic allocation
42 };
43 
44 /*
45  Test case for STokenize class
46  @param none
47  */
48 inline void testSTokenize()
49 {
50  std::cout << "--- Testing STokenize -----\n";
51  Token mySweetToken;
52 // string testString = "âɔīīī 3123 ɔâīīī sdas dijas"; // Fail testcase
53  string testString = "apple is red, bannana is yellow";
54  try {
55  STokenize mySTokenize(testString);
56  while (mySTokenize.More()) {
57  mySweetToken = mySTokenize.nextToken();
58  cout << "token : " << mySweetToken << endl;
59  }
60  } catch (const char* e) {
61  cout << "something went wrong : " << "STokenize" << endl;
62  }
63  cout << "-------- End of STokenize test case -----\n\n";
64 }
65 
66 #endif // STOKENIZE_H
Definition: stokenize.h:13
Definition: token.h:41