akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 1 | #ifndef NLSR_TOKENIZER_HPP |
2 | #define NLSR_TOKENIZER_HPP | ||||
3 | |||||
4 | #include <iostream> | ||||
5 | #include <boost/tokenizer.hpp> | ||||
6 | #include <boost/algorithm/string.hpp> | ||||
7 | #include <string> | ||||
8 | #include <list> | ||||
9 | #include <vector> | ||||
10 | #include <ndn-cpp-dev/face.hpp> | ||||
11 | |||||
12 | namespace nlsr | ||||
13 | { | ||||
14 | |||||
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 15 | using namespace std; |
16 | using namespace boost; | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 17 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 18 | class nlsrTokenizer |
19 | { | ||||
20 | public: | ||||
21 | nlsrTokenizer(const string& inputString) | ||||
22 | : firstToken() | ||||
23 | , restOfTheLine() | ||||
24 | , currentPosition(0) | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 25 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 26 | seps = " "; |
27 | originalString = inputString; | ||||
28 | makeToken(); | ||||
29 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 30 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 31 | nlsrTokenizer(const string& inputString, const string& separator) |
32 | : firstToken() | ||||
33 | , restOfTheLine() | ||||
34 | , currentPosition(0) | ||||
35 | { | ||||
36 | seps = separator; | ||||
37 | originalString = inputString; | ||||
38 | makeToken(); | ||||
39 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 40 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 41 | string getFirstToken() |
42 | { | ||||
43 | return firstToken; | ||||
44 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 45 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 46 | string getRestOfLine() |
47 | { | ||||
48 | return restOfTheLine; | ||||
49 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 50 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 51 | void resetCurrentPosition(uint32_t cp=0) |
52 | { | ||||
53 | if( cp >=0 && cp <= vTokenList.size() ) | ||||
54 | { | ||||
55 | currentPosition=cp; | ||||
56 | } | ||||
57 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 58 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 59 | string getNextToken() |
60 | { | ||||
61 | if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1)) | ||||
62 | { | ||||
63 | return vTokenList[currentPosition++]; | ||||
64 | } | ||||
65 | return ""; | ||||
66 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 67 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 68 | uint32_t getTokenNumber() |
69 | { | ||||
70 | return tokenList.size(); | ||||
71 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 72 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 73 | string getToken(int position) |
74 | { | ||||
75 | if( position >=0 && position <vTokenList.size() ) | ||||
76 | { | ||||
77 | return vTokenList[position]; | ||||
78 | } | ||||
79 | return ""; | ||||
80 | } | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 81 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 82 | int getTokenPosition(string& token); |
83 | string getTokenString(int from , int to); | ||||
84 | string getTokenString(int from); | ||||
85 | bool doesTokenExist(string token); | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 86 | |
87 | |||||
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 88 | private: |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 89 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 90 | void makeToken(); |
91 | void insertToken(const string& token); | ||||
92 | void makeRestOfTheLine(); | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 93 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 94 | string seps; |
95 | string originalString; | ||||
96 | string firstToken; | ||||
97 | string restOfTheLine; | ||||
98 | std::list<string> tokenList; | ||||
99 | std::vector<string> vTokenList; | ||||
100 | uint32_t currentPosition; | ||||
101 | }; | ||||
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 102 | |
103 | }//namespace nlsr | ||||
104 | #endif |