//#  eulerN -- program for statistical estimation of Euler characteristic of a 3-dimensional body
//#  given as a sufficiently dense "volumetric" point sampling
//#
//#  Copyright (c) 2005-2007 Bradford Jones, Konstantin Rybnikov, Karen Daniels, Daniel Klain
//#  Release 2: 1 June 2007 
//#
//#  This program is free software; you can redistribute it and/or modify it
//#  under the terms of the GNU General Public License as published by the
//#  Free Software Foundation; either version 2, or (at your option) any
//#  later version: http://www.gnu.org/licenses/gpl.txt.
//#
//#  This program is distributed in the hope that it will be useful,
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//#  GNU General Public License for more details.
//#-----------------------------------------------------------------------------


////////////////
// A simple string tokenizer class that uses C++ string objects for ease of use
// tokenizer(string a, string b) where string a is the string to be tokenized and
// string b is a string where each character represents a separator
////////////////
#ifndef TOKENIZER
#define TOKENIZER
	#include <vector>
	#include <string>
	using namespace std;

class tokenizer
{
	private:
		vector<string> data;
		int tokenindex;
	public:
		// constructors
		tokenizer()
		{
			tokenindex = 0;
		}
		tokenizer(string a, string b)
		{
			tokenize(a, b);
		}
		// member functions
		void tokenize(string a, string b)
		{
			data.clear();
			tokenindex = 0;
			int startToken = 0;
			int tokenLength = 0;

			for (int i = 0; i < a.size(); i++)
			{
				bool d = false;
				for (int j = 0; j < b.size(); j++)
					if (a[i] == b[j])
					{
						d = true;
						break;
					}
				if (d)
				{
					string token = a.substr(startToken, tokenLength);
					if (token.empty() == false)
						data.push_back(token);
					startToken = i + 1;
					tokenLength = 0;
				}
				else
					tokenLength++;
			}
			if (startToken < a.size())
			{
				string token = a.substr(startToken);
				if (token.empty() == false)
					data.push_back(token);
			}
		}
		int size()
		{
			return data.size();
		}
		string& operator[] (int index)
		{
			return data[index];
		}
};
#endif
