/*
	Trig Wars.
	Copyright (c) 2008, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef STRING_UTIL_H
#define STRING_UTIL_H

//=====================================================================================================================
//=====================================================================================================================

#include "Base\Types.h"
#include <string>
#include <list>

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	/// @brief		Static class containing helper functions for operating on strings
	//=================================================================================================================
	
	class String
	{	
		public:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Tells if the string contains only a number

				static inline bool IsNumeric( const std::string & s ){ return IsNumeric(s.c_str()); }
				
				/// Tells if the string contains only a number
				
				static bool IsNumeric( const char * s );		
				
				/// Tells if the string contains only an integer
				
				static inline bool IsInteger( const std::string & s ){ return IsInteger(s.c_str()); }
				
				/// Tells if the string contains only an integer
				
				static bool IsInteger( const char * s );
				
				/// Tells if the string contains only a boolean
				
				static inline bool IsBoolean( const std::string & s ){ return IsBoolean(s.c_str()); }
				
				/// Tells if the string contains only a boolean
				
				static bool IsBoolean( const char * s );
			
				/// Makes the given string uppercase

				static inline void ToUpper( std::string & s ){ ToUpper( (char*) s.c_str() ); }
				
				/// Makes the given string uppercase
				
				static void ToUpper( char * s );
				
				/// Makes the given string lowercase
				
				static inline void ToLower( std::string & s ){ ToLower( (char*) s.c_str() ); }

				/// Makes the given string lowercase
				
				static void ToLower( char * s );
				
				/// Attempts to convert string to a boolean, returns default value on failure

				static inline bool ToBool( const std::string & s , bool default_value = false )
				{ 
					return ToBool(s.c_str(),default_value);
				}
				
				/// Attempts to convert string to a boolean, returns default value on failure

				static bool ToBool( const char * s , bool default_value = false );
				
				/// Attempts to convert string to a boolean, throws a std::exception exception on error

				static bool ToBoolCritical( const char * s );
				
				/// Attempts to convert string to a boolean, throws a std::exception exception on error

				static inline bool ToBoolCritical( const std::string & s )
				{ 
					return ToBoolCritical(s.c_str());
				}				
				
				/// Attempts to convert string to an integer, returns default value on failure
				
				static inline int ToInt( const std::string & s , int default_value = 0 )
				{
					return ToInt(s.c_str(),default_value);
				}
				
				/// Attempts to convert string to an integer, returns default value on failure
				
				static int ToInt( const char * s , int default_value = 0 );
				
				/// Attempts to convert string to an integer, throws a std::exception on error
				
				static int ToIntCritical( const char * s );
				
				/// Attempts to convert string to an integer, throws a std::exception on error
				
				static int ToIntCritical( const std::string & s )
				{
					return ToIntCritical(s.c_str());
				}						
				
				/// Attempts to convert string to a float, returns default value on failure
				
				static inline float ToFloat( const std::string & s , float default_value = 0 )
				{
					return ToFloat(s.c_str(),default_value);
				}
				
				/// Attempts to convert string to a float, returns default value on failure
				
				static float ToFloat( const char * s , float default_value = 0 );
				
				/// Attempts to convert string to a float, throws a std::exception on error
				
				static float ToFloatCritical( const char * s );
				
				/// Attempts to convert string to a float, throws a std::exception on error
				
				static float ToFloatCritical( const std::string & s )
				{
					return ToFloatCritical( s.c_str() );
				}
				
				/// Converts the given boolean to a string
				
				static std::string ToString( bool value );
				
				/// Converts the given integer to a string
				
				static std::string ToString( int value );
				
				/// Converts the given float to a string
				
				static std::string ToString( float value );
				
				/// Tells if the given string is a valid name for a variable according to the C/C++ languages
				
				static bool IsValidVariableName( const char * name );
				
				/// Tells if the given string is a valid name for a variable according to the C/C++ languages
				
				static inline bool IsValidVariableName( const std::string & name ){ return IsValidVariableName( name.c_str() ); }
				
				/// Splits a string on the specified character saving resultant strings to the given list
				
				static void Split( const char * text , char c , std::list<std::string> & results );
				
				/// Splits a string on the specified character saving resultant strings to the given list
				
				static inline void Split( const std::string & text , char c , std::list<std::string> & results )
				{
					Split( text.c_str() , c , results );
				}				
	};
}

#endif
