//File Functions.h - contains miscellaneous functions that don't belong in a class
//Functions in this file are recreations of Java's string functions

//Make sure the file hasn't been included already
#ifndef _stringfunctions_h
#define _stringfunctions_h

#include <iostream>
#include <string>

using namespace std;

//IsWhitespace function
bool IsWhitespace(char c){
	if(c == '\n')
		return true;
	if(c == ' ')
		return true;
	if(c == '\t')
		return true;

	return false;
}

//Trim function
string Trim(string s){
	//find leading whitespace characters, then get rid of them
	while(IsWhitespace(s[0]) == true){
		char * temp;
		temp = new char[s.size()];
		size_t length = s.copy(temp, 1, s.size());
		temp[length]='\0';
		s = temp;
		delete temp;
	}
	//Find trailing whitespace characters, then get rid of them
	while(IsWhitespace(s[s.size()-1]) == true){
		char * temp;
		temp = new char[s.size()];
		size_t length = s.copy(temp, 0, s.size() - 1);
		temp[length]='\0';
		s = temp;
		delete temp;
	}
	return s;
}

//StartsWith function
bool StartsWith(string str, string substr){
	if(str.compare(0, substr.size(), substr) == 0)
		return true;
	else
		return false;
}

//Contains function
bool Contains(string str, string substr){
	if(str.find_first_of(substr) >= 0)
		return true;
	else
		return false;
}

//LowerCase function
string LowerCase(string s){
	for(size_t i=0; i<s.size(); i++){
		if(s[i] >= 'A' && s[i] <= 'Z'){
			s[i] += 32;
		}
	}
	return s;
}
#endif
//End of StringFunctions.h