blob: dd6254d1d8ed4ca8e3d4b3911699e436ebc57996 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#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
14class Tokenizer
15{
16public:
17 Tokenizer(const std::string& inputString)
18 : m_firstToken()
19 , m_restOfTheLine()
20 , m_currentPosition(0)
21 {
22 m_seps = " ";
23 m_originalString = inputString;
24 makeToken();
25 }
26
27 Tokenizer(const std::string& inputString, const std::string& separator)
28 : m_firstToken()
29 , m_restOfTheLine()
30 , m_currentPosition(0)
31 {
32 m_seps = separator;
33 m_originalString = inputString;
34 makeToken();
35 }
36
37 std::string
38 getFirstToken()
39 {
40 return m_firstToken;
41 }
42
43 std::string
44 getRestOfLine()
45 {
46 return m_restOfTheLine;
47 }
48
49 void
50 resetCurrentPosition(uint32_t cp = 0)
51 {
52 if (cp <= m_vTokenList.size())
53 {
54 m_currentPosition = cp;
55 }
56 }
57
58 std::string
59 getNextToken()
60 {
61 if (m_currentPosition <= (m_vTokenList.size() - 1))
62 {
63 return m_vTokenList[m_currentPosition++];
64 }
65 return "";
66 }
67
68 uint32_t
69 getTokenNumber()
70 {
71 return m_tokenList.size();
72 }
73
74 std::string
75 getToken(unsigned int position)
76 {
77 if (position < m_vTokenList.size())
78 {
79 return m_vTokenList[position];
80 }
81 return "";
82 }
83
84 uint32_t
85 getTokenPosition(std::string& token);
86
87 std::string
88 getTokenString(uint32_t from , uint32_t to);
89
90 std::string
91 getTokenString(uint32_t from);
92
93 bool
94 doesTokenExist(std::string token);
95
96
97private:
98
99 void
100 makeToken();
101
102 void
103 insertToken(const std::string& token);
104
105 void
106 makeRestOfTheLine();
107
108 std::string m_seps;
109 std::string m_originalString;
110 std::string m_firstToken;
111 std::string m_restOfTheLine;
112 std::list<std::string> m_tokenList;
113 std::vector<std::string> m_vTokenList;
114 uint32_t m_currentPosition;
115};
116
117}//namespace nlsr
118#endif //NLSR_TOKENIZER_HPP