#include <iostream>
#include <string>
#include <vector>
#include "strlib.h"
using namespace std;


namespace StrLib {

string test()
{
	string s("Hey!");
	return s;	
}

string oneArg(string& arg)
{
	string s, buf;

	for ( string::iterator c = arg.begin(); c != arg.end(); c++ ) {
		s = *c;
		if (s == " ") break;
		else buf += s;
	}
			
	arg.replace(0,buf.length()+1, "");
	return buf;
}

bool isMatch(const string& arg, const string& str)
{
	vector<string> alist = argList(str);
	vector<string>::const_iterator s;

	for ( s = alist.begin(); s != alist.end(); s++ ) {
		if (isPrefix(arg, *s))
			return true;
	}

	return false;
}

bool isPrefix(const string& arg, const string& str)
{
	string buf;
	buf.assign(str, 0, arg.length());
	if (toLower(buf) == toLower(arg)) return true;
	else return false;
}

string toLower(const string& str) 
{
	string buf, s;
	s += str;
	for ( string::iterator c = s.begin(); c != s.end(); c++ ) { buf += tolower(*c); }
	return buf;
}

string toUpper(const string& str) 
{
	string buf, s;
	s += str;
	for ( string::iterator c = s.begin(); c != s.end(); c++ ) { buf += toupper(*c); }
	return buf;
}

vector<string> argList(const string& str)
{
	string buf, s;
	vector<string> v;
	string::const_iterator c; 

	s += str; s += ' ';
	for ( c = s.begin(); c != s.end(); c++ ) {
		if ( *c != ' ' ) buf += *c;
		else {
			v.push_back(buf);
			buf = "";
		}
	}

	return v;
}


};