#include "parse.h"

// return the number of tokens read.
int parse(parseCont& tokens, char sep, const string& input)
{
  string::size_type start=0;
  string::size_type end;
  int i;

  tokens.clear();

  for (i=0; (end = input.find(sep, start)) != input.npos; i++, start=end+1)
    tokens.push_back(input.substr(start,end-start));
  
  tokens.push_back(input.substr(start));

  return i+1;
}

int esrap(const parseCont& tokens, char sep, string& output)
{
  parseCont::const_iterator i;

  output.erase();

  for(i=tokens.begin(); i != tokens.end(); i++)
    output += *i + sep;

  if (*(output.rbegin()) == sep)
    output.erase(output.end() -1);

  return tokens.size();
}

/*
 example usage and test main:

int main()
{
  parseCont tokens;
  string input;
  int num;

  getline(cin,input);
  while(cin) {
    num=parse(tokens,':',input);

    for (int i=0;i<num;i++)
      cout << tokens[i] << " ";
    cout << endl;

    num=esrap(tokens,'+',input);
    cout << input << endl;

    getline(cin,input);
  }
}
*/

  
  
  


