blob: 6cd97e08394e0b2c5b1fe529f1ae408091ff114e [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
15 using namespace std;
16 using namespace boost;
17
18 class nlsrTokenizer
19 {
20 public:
21 nlsrTokenizer(const string& inputString)
22 : firstToken()
23 , restOfTheLine()
24 , currentPosition(0)
25 {
26 seps = " ";
27 originalString = inputString;
28 makeToken();
29 }
30
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 }
40
41 string getFirstToken()
42 {
43 return firstToken;
44 }
45
46 string getRestOfLine()
47 {
48 return restOfTheLine;
49 }
50
51 void resetCurrentPosition(uint32_t cp=0)
52 {
53 if( cp >=0 && cp <= vTokenList.size() )
54 {
55 currentPosition=cp;
56 }
57 }
58
59 string getNextToken()
60 {
61 if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
62 {
63 return vTokenList[currentPosition++];
64 }
65 return "";
66 }
67
68 uint32_t getTokenNumber()
69 {
70 return tokenList.size();
71 }
72
73 string getToken(int position)
74 {
75 if( position >=0 && position <vTokenList.size() )
76 {
77 return vTokenList[position];
78 }
79 return "";
80 }
81
82 int getTokenPosition(string& token);
83 string getTokenString(int from , int to);
84 string getTokenString(int from);
85 bool doesTokenExist(string token);
86
87
88 private:
89
90 void makeToken();
91 void insertToken(const string& token);
92 void makeRestOfTheLine();
93
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 };
102
103}//namespace nlsr
104#endif