blob: 4b84d8bc89a352a94b19921d4afcedb01d4080d6 [file] [log] [blame]
#ifndef NLSR_TOKENIZER_HPP
#define NLSR_TOKENIZER_HPP
#include <iostream>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <string>
#include <list>
#include <vector>
#include <ndn-cpp-dev/face.hpp>
namespace nlsr
{
using namespace std;
using namespace boost;
class nlsrTokenizer
{
public:
nlsrTokenizer(const string& inputString)
: firstToken()
, restOfTheLine()
, currentPosition(0)
{
seps = " ";
originalString = inputString;
makeToken();
}
nlsrTokenizer(const string& inputString, const string& separator)
: firstToken()
, restOfTheLine()
, currentPosition(0)
{
seps = separator;
originalString = inputString;
makeToken();
}
string getFirstToken()
{
return firstToken;
}
string getRestOfLine()
{
return restOfTheLine;
}
void resetCurrentPosition(uint32_t cp=0)
{
if( cp >=0 && cp <= vTokenList.size() )
{
currentPosition=cp;
}
}
string getNextToken()
{
if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
{
return vTokenList[currentPosition++];
}
return "";
}
uint32_t getTokenNumber()
{
return tokenList.size();
}
string getToken(int position)
{
if( position >=0 && position <vTokenList.size() )
{
return vTokenList[position];
}
return "";
}
int getTokenPosition(string& token);
string getTokenString(int from , int to);
string getTokenString(int from);
bool doesTokenExist(string token);
private:
void makeToken();
void insertToken(const string& token);
void makeRestOfTheLine();
string seps;
string originalString;
string firstToken;
string restOfTheLine;
std::list<string> tokenList;
std::vector<string> vTokenList;
uint32_t currentPosition;
};
}//namespace nlsr
#endif