#include "Parser.h"
#include "Main.h"
#include <string>

string Parser::GetFirst(string _in)
{
	string::size_type wordEnd = 0;
	wordEnd = _in.find(" ");
	return _in.substr(0, wordEnd);
}

bool Parser::First(string aInput, string aWord)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	//Stops if nothing is put in
	if (GetFirst(aInput) == "")
		return false;

	//Returns 0 if the strings are the same
	if (!GetFirst(aInput).compare(aWord))
		return true;

	return false;
}

bool Parser::First(string aInput, string aWord, string aWord2)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	//Returns 0 if the strings are the same
	if (!GetFirst(aInput).compare(aWord) || !GetFirst(aInput).compare(aWord2))
		return true;

	return false;
}

bool Parser::First(string aInput, string aWord, string aWord2, string aWord3)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	//Returns 0 if the strings are the same
	if (!GetFirst(aInput).compare(aWord) || !GetFirst(aInput).compare(aWord2) || !GetFirst(aInput).compare(aWord3))
		return true;

	return false;
}


bool Parser::Next(string aInput, string aWord)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	if (aInput.find(aWord) != string::npos)
		return true;

	return false;
}

bool Parser::Next(string aInput, string aWord, string aWord2)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	if (aInput.find(aWord) != string::npos || aInput.find(aWord2) != string::npos)
		return true;

	return false;
}

bool Parser::Next(string aInput, string aWord, string aWord2, string aWord3)
{
	aInput = ToLower(aInput);
	aWord = ToLower(aWord);

	if (aInput.find(aWord) != string::npos || aInput.find(aWord2) != string::npos || aInput.find(aWord3) != string::npos)
		return true;

	return false;
}

/*
bool Parser::Next(string aInput, string aWord)
{
	aInput = ToLower(aInput);

	string::size_type wordEnd = 0;
	string::size_type wordStart = 0;
	string s;

	wordEnd = aInput.find(" ");

	while (wordEnd != string::npos)
	{
		wordStart = wordEnd;
		wordEnd = aInput.find(" ", wordStart + 1);

		if (wordEnd - wordStart > 1 || wordStart == 0 || wordEnd == string::npos)
		{
			s = aInput.substr(wordStart + 1, wordEnd - wordStart);

			if (!s.compare(aWord))
				return true;
		}
	}

	return false;
}

bool Parser::Next(string aInput, string aWord, string aWord2)
{
	aInput = ToLower(aInput);

	string::size_type wordEnd = 0;
	string::size_type wordStart = 0;
	string s;

	wordEnd = aInput.find(" ");

	while (wordEnd != string::npos)
	{
		wordStart = wordEnd;
		wordEnd = aInput.find(" ", wordStart + 1);

		if (wordEnd - wordStart > 1 || wordStart == 0 || wordEnd == string::npos)
		{
			s = aInput.substr(wordStart + 1, wordEnd - wordStart);

			if (!s.compare(aWord) || !s.compare(aWord2))
				return true;
		}
	}

	return false;
}

bool Parser::Next(string aInput, string aWord, string aWord2, string aWord3)
{
	aInput = ToLower(aInput);

	string::size_type wordEnd = 0;
	string::size_type wordStart = 0;
	string s;

	wordEnd = aInput.find(" ");

	while (wordEnd != string::npos)
	{
		wordStart = wordEnd;
		wordEnd = aInput.find(" ", wordStart + 1);

		if (wordEnd - wordStart > 1 || wordStart == 0 || wordEnd == string::npos)
		{
			s = aInput.substr(wordStart + 1, wordEnd - wordStart);

			if (!s.compare(aWord) || !s.compare(aWord2) || !s.compare(aWord3))
				return true;
		}
	}

	return false;
}
*/
string Parser::ToLower(string _lower)
{
	for(unsigned int i = 0; i < _lower.length(); ++i)
		_lower[i] = tolower(_lower[i]);

	return _lower;
}