// ----------------------------------------------------------------------------------



// ----------------------------------------------------------------------------------





#include "CCase.h"

#include <ctype.h>



//#define TEST



CCase::CCase()

	: UExtended()

{

}



CCase::~CCase()

{

}



void 

CCase::WordLower(char *Word)

{

	short Length;

	short i;

 

	Length = strlen(Word);

	for (i=0; i<Length; i++)	

	{

		Word[i] = EToLower(Word[i]);

	}

}



void 

CCase::WordUpper(char *Word)

{

	short Length;

	short i;



	Length = strlen(Word);

	for (i=0; i<Length; i++)	

	{

		Word[i] = EToUpper(Word[i]);

	}

}



short 

CCase::CaseCheckWord(char *Word)

{

	short Length;

	

	Length = strlen(Word);

	

	if(Length <2) 

	{

		if(EIsUpper(Word[0]))

			return UPPER_CASE;

		else 

			return lower_case;

	}



	if(Length > 2) 

	{



		 /************ CHECK FOR lower lower lower *****************/

	

		if((EIsLower(Word[0])) && (EIsLower(Word[1])) && (EIsLower(Word[2])))

			return lower_case;

	

		 /************ CHECK FOR UPPER UPPER UPPER *****************/

	

		if((EIsUpper(Word[0])) && (EIsUpper(Word[1])) && (EIsUpper(Word[2])))

			return UPPER_CASE;

	

		 /************ CHECK FOR UPPER UPPER lower *****************/

	

		if((EIsUpper(Word[0])) && (EIsUpper(Word[1])) && (EIsLower(Word[2])))

			return (UPPER_UPPER_lower);

	

	

		 /************ CHECK FOR lower UPPER lower *****************/

	

		if((EIsLower(Word[0])) && (EIsUpper(Word[1])) && (EIsLower(Word[2])))

			return (lower_UPPER_lower);

	

		 /************ CHECK FOR lower UPPER UPPER *****************/

	

		if((EIsLower(Word[0])) && (EIsUpper(Word[1])) && (EIsUpper(Word[2])))

			return (lower_UPPER_UPPER);

	

		 /************ CHECK FOR lower lower UPPER *****************/

	

		if((EIsLower(Word[0])) && (EIsLower(Word[1])) && (EIsUpper(Word[2])))

			return lower_lower_UPPER;



	} // if



	/************** CHECK FOR lower UPPER ***********************/

	

	if(EIsLower(Word[0]) && EIsUpper(Word[1])) 

		return lower_UPPER;

	

	/************** CHECK FOR lower case  ***********************/

	

	if((EIsLower(Word[0])) && (EIsLower(Word[1]))) 

		return lower_case;

	

	/************** CHECK FOR UPPER CASE  ***********************/

	

	if((EIsUpper(Word[0])) && (EIsUpper(Word[1]))) 

		return UPPER_CASE;

		

	/************** UPPER lower *********************************/

	return UPPER_lower; 

}





void 

CCase::FixCase(char *Word, short CaseCode)

{

	switch(CaseCode) 

	{

	

	

		/********** CONVERT TO "Word" *************/

		case UPPER_UPPER_lower:

		case lower_UPPER_lower:

		case UPPER_lower:

			WordLower(Word);

			Word[0]=toupper(Word[0]);

			break;

	

		/********** CONVERT TO "WORD" *************/

		case UPPER_CASE       :

		case lower_UPPER_UPPER:WordUpper(Word);

			break;

	

		/********** CONVERT TO "word" *************/

		case lower_case       :

		case lower_lower_UPPER:WordLower(Word);

			break;

	

		/********** CONVERT TO "It" ***************/

		case lower_UPPER:Word[0]=toupper(Word[0]);

			Word[1]=tolower(Word[1]);

			break;

	

		default: 

			break;

	} // switch

}







#ifdef TEST



short main()

     {

      char Choice[20];

      short  Result;

      char Word[40];

      short  CaseType;



      CCase CaseCheck;



      for(;;) {

       printf("\n\n1) Enter a word for case checking");

       printf("\n2) Case Convert a word");

       printf("\n0) Quit\n");

       gets(Choice);



       Result = atoi(Choice);

       switch(Result) {

	case 1:

	       printf("\n Word to case check :");

	       gets(Word);

	       CaseType = CaseCheck.CaseCheckWord(Word);

	       printf("\nWord has the following case : %d",CaseType);

	       break;

	case 2:

	       printf("\nWord to case Convert :");

	       gets(Word);

	       printf("\nCase type to convert to [1-5] :");

	       gets(Choice);

	       CaseType = atoi(Choice);

	       CaseCheck.FixCase(Word,CaseType);

	       printf("\nCase converted word is : %s",Word);

	       break;

	case 0:

	       exit(1);

       }; // end switch

      } // end for(;;)



     } // end main



#endif




