#include "Name.h"
#include <string>

Name::Name()
{

}

Name::Name(char *str) : std::string(str)
{

}

Name::Name(std::string str) : std::string(str)
{

}

Name::Name(Name *name)
{
    /* The assign opertor requires a reference, this is created
     * when we give it the actual object as a paramter
     */
    this->assign(*name);
}

/* Validation is just a search for characters which should not be there */
bool Name::validate()
{
    int stringLenght = this->length(); // Name is a kind of string, we can use its methods.
    int i=0;
    bool found = false;

    /* I could be using iterators here but I don't want to go too far */
    while(i < stringLenght && found == false)
    {
        //Check char is a - z, A-Z or hyphen or dot (Billy-Joe Jr.)

        char current = this->at(i);

        if(current < 'A')
        {
            //is it a - or a .
            if(current == '-' || current == '.' || current == ' ')
            {
                //these are valid chars
            }
            else
            {
                found = true;
            }
        }
        else
        {
            if(current > 'Z')
            {
                //Not upper case
                if(current < 'a')
                {
                    //between upper and lower
                    found = true;
                }
                else
                {
                    if(current > '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 */
}
