blob: 4b84d8bc89a352a94b19921d4afcedb01d4080d6 [file] [log] [blame]
akmhoqueba094742014-02-28 11:47:21 -06001#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
12namespace nlsr
13{
14
akmhoque5a44dd42014-03-12 18:11:32 -050015 using namespace std;
16 using namespace boost;
akmhoqueba094742014-02-28 11:47:21 -060017
akmhoque5a44dd42014-03-12 18:11:32 -050018 class nlsrTokenizer
19 {
20 public:
21 nlsrTokenizer(const string& inputString)
22 : firstToken()
23 , restOfTheLine()
24 , currentPosition(0)
akmhoqueba094742014-02-28 11:47:21 -060025 {
akmhoque5a44dd42014-03-12 18:11:32 -050026 seps = " ";
27 originalString = inputString;
28 makeToken();
29 }
akmhoqueba094742014-02-28 11:47:21 -060030
akmhoque5a44dd42014-03-12 18:11:32 -050031 nlsrTokenizer(const string& inputString, const string& separator)
32 : firstToken()
33 , restOfTheLine()
34 , currentPosition(0)
35 {
36 seps = separator;
37 originalString = inputString;
38 makeToken();
39 }
akmhoqueba094742014-02-28 11:47:21 -060040
akmhoque5a44dd42014-03-12 18:11:32 -050041 string getFirstToken()
42 {
43 return firstToken;
44 }
akmhoqueba094742014-02-28 11:47:21 -060045
akmhoque5a44dd42014-03-12 18:11:32 -050046 string getRestOfLine()
47 {
48 return restOfTheLine;
49 }
akmhoqueba094742014-02-28 11:47:21 -060050
akmhoque5a44dd42014-03-12 18:11:32 -050051 void resetCurrentPosition(uint32_t cp=0)
52 {
53 if( cp >=0 && cp <= vTokenList.size() )
54 {
55 currentPosition=cp;
56 }
57 }
akmhoqueba094742014-02-28 11:47:21 -060058
akmhoque5a44dd42014-03-12 18:11:32 -050059 string getNextToken()
60 {
61 if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
62 {
63 return vTokenList[currentPosition++];
64 }
65 return "";
66 }
akmhoqueba094742014-02-28 11:47:21 -060067
akmhoque5a44dd42014-03-12 18:11:32 -050068 uint32_t getTokenNumber()
69 {
70 return tokenList.size();
71 }
akmhoqueba094742014-02-28 11:47:21 -060072
akmhoque5a44dd42014-03-12 18:11:32 -050073 string getToken(int position)
74 {
75 if( position >=0 && position <vTokenList.size() )
76 {
77 return vTokenList[position];
78 }
79 return "";
80 }
akmhoqueba094742014-02-28 11:47:21 -060081
akmhoque5a44dd42014-03-12 18:11:32 -050082 int getTokenPosition(string& token);
83 string getTokenString(int from , int to);
84 string getTokenString(int from);
85 bool doesTokenExist(string token);
akmhoqueba094742014-02-28 11:47:21 -060086
87
akmhoque5a44dd42014-03-12 18:11:32 -050088 private:
akmhoqueba094742014-02-28 11:47:21 -060089
akmhoque5a44dd42014-03-12 18:11:32 -050090 void makeToken();
91 void insertToken(const string& token);
92 void makeRestOfTheLine();
akmhoqueba094742014-02-28 11:47:21 -060093
akmhoque5a44dd42014-03-12 18:11:32 -050094 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 };
akmhoqueba094742014-02-28 11:47:21 -0600102
103}//namespace nlsr
104#endif