#include "Name.h"
#include "string.h"

Name::Name() : MyString()
{

}

Name::Name(char *str) : MyString(str)
{

}

/* This looks a bit dogy because it is, using the copy constructor copy the stuff into name.
 * Should actually work fine as Name only extends MyString */
Name::Name(MyString * myString) : MyString(myString)
{

}

Name::Name(Name * name)
{
    /* this only works in the copy constructor */
    this->setString(name->str);
}

/* Validation is just a search for characters which should not be there */
bool Name::validate()
{
    int stringLenght = strlen(str);
    int i=0;
    bool found = false;

    while(i < stringLenght && found == false)
    {
        //Check char is a - z, A-Z or hyphen or dot (Billy-Joe Jr.)

        if(str[i] < 'A')
        {
            //is it a - or a .
            if(str[i] == '-' || str[i] == '.' || str[i] == ' ')
            {
                //these are valid chars
            }
            else
            {
                found = true;
            }
        }
        else
        {
            if(str[i] > 'Z')
            {
                //Not upper case
                if(str[i] < 'a')
                {
                    //between upper and lower
                    found = true;
                }
                else
                {
                    if(str[i] > 'z')
                    {
                        //Not lower case
                        found = true;
                    }
                    else
                    {
                        //lower case.
                    }
                }
            }
            else
            {
                //above A but less then Z we have an upper case
            }
        }


        i++;
    }

   if(found == true)
       return false;
   else
       return true;
}


Name::~Name()
{
    /* Don't need anything here the parent constructor is virtual */
}
