//----------------------- CSPString.h -------------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************

#ifndef _CSPSTRING
#define _CSPSTRING

#include "CSPConf.h"
#include "CSPObject.h"
#include <string>
#include <locale.h>
#include <mbctype.h>

#ifdef _GCC_
#undef min
#undef max
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#endif


class CSPLIB_CLASS_EXPORT CSPDate;
class CSPLIB_CLASS_EXPORT CSPDateTime;
class CSPLIB_CLASS_EXPORT CSPTime;
class CSPLIB_CLASS_EXPORT CSPWString;
class CSPLIB_CLASS_EXPORT CSPVariant;

class CSPLIB_CLASS_EXPORT CSPString : public CSPObject
{
	friend class CSPLIB_CLASS_EXPORT CSPWString;
	
	public:
		enum{ NOT_FOUND = 0xFFFFFFFFUL };

		void URLDecode();
		void URLEncode();
		void HTMLDecode();
		void HTMLEncode();
		char GetChar( unsigned long ulPos )  const;
		void SetChar( unsigned long ulPos, char chChar );
		void Add( const void* pData, unsigned long ulLen );
		unsigned long Length() const;
		void SetSize( unsigned long ulNewSize );
		void Empty();
		void Clear();
		void UpperCase();
		void LowerCase();
		unsigned long Find( const char* pszSubString, unsigned long ulStartPos = 0 ) const;
		unsigned long Find( const CSPString& strSubString, unsigned long ulStartPos = 0 ) const;
		long CompareNoCase( const CSPString& strString ) const;
		long CompareNoCase( const char* pszString ) const;
		CSPString Mid( unsigned long ulStartPos, unsigned long ulLength ) const;
		int GetIntVal() const;
		__int64 GetInt64Val() const;
		double GetDoubleVal() const;
		unsigned long Replace( const CSPString& strFind, const CSPString& strReplace, unsigned long ulFirst = 0 );
		const char* GetPtr() const;

		CSPString();
		virtual ~CSPString();

		CSPString( const char* pszString );
		CSPString( const wchar_t* pwszString );
		CSPString( const CSPString& strString );
		CSPString( const CSPWString& wstrString );
		CSPString( const std::string& strString );
#if !defined _GCC_
		CSPString( const std::wstring& wstrString );
#endif
		CSPString( const CSPVariant& varValue );
		CSPString( long double ldblNumber );
		CSPString( double dblNumber );
		CSPString( float fFloat );
		CSPString( long lNumber );
		CSPString( unsigned long ulNumber );
		CSPString( int iNumber );
		CSPString( unsigned int uiNumber );
		CSPString( __int64 i64Number );
		CSPString( unsigned __int64 ui64Number );
		CSPString( bool bBool );
		CSPString( const CSPDate& dDate );
		CSPString( const CSPDateTime& dtDateTime );
		CSPString( const CSPTime& tTime );

		CSPString& operator = ( const char* pszString );
		CSPString& operator = ( const wchar_t* pwszString );
		CSPString& operator = ( const CSPString& strString );
		CSPString& operator = ( const CSPWString& wstrString );
		CSPString& operator = ( const std::string& strString );
#if !defined _GCC_
		CSPString& operator = ( const std::wstring& wstrString );
#endif
		CSPString& operator = ( const CSPVariant& varValue );
		CSPString& operator = ( long double ldblNumber );
		CSPString& operator = ( double dblNumber );
		CSPString& operator = ( float fNumber );
		CSPString& operator = ( long lNumber );
		CSPString& operator = ( unsigned long ulNumber );
		CSPString& operator = ( int iNumber );
		CSPString& operator = ( unsigned int uiNumber );
		CSPString& operator = ( __int64 i64Number );
		CSPString& operator = ( unsigned __int64 ui64Number );
		CSPString& operator = ( bool bBool );
		CSPString& operator = ( const CSPDate& dDate );
		CSPString& operator = ( const CSPDateTime& dtDateTime );
		CSPString& operator = ( const CSPTime& tTime );

		CSPString& operator += ( const char* pszString );
		CSPString& operator += ( const wchar_t* pwszString );
		CSPString& operator += ( const CSPString& strString );
		CSPString& operator += ( const CSPWString& wstrString );
		CSPString& operator += ( const std::string& strString );
#if !defined _GCC_
		CSPString& operator += ( const std::wstring& wstrString );
#endif
		CSPString& operator += ( const CSPVariant& varValue );
		CSPString& operator += ( char cChar );
		CSPString& operator += ( long double ldblNumber );
		CSPString& operator += ( double dblNumber );
		CSPString& operator += ( float fNumber );
		CSPString& operator += ( long lNumber );
		CSPString& operator += ( unsigned long ulNumber );
		CSPString& operator += ( int iNumber );
		CSPString& operator += ( unsigned int uiNumber );
		CSPString& operator += ( __int64 i64Number );
		CSPString& operator += ( unsigned __int64 ui64Number );
		CSPString& operator += ( bool bBool );
		CSPString& operator += ( const CSPDate& dDate );
		CSPString& operator += ( const CSPDateTime& dtDateTime );
		CSPString& operator += ( const CSPTime& tTime );

		CSPString operator + ( const char* pszString ) const;
		CSPString operator + ( const wchar_t* pwszString ) const;
		CSPString operator + ( const CSPString& strString ) const;
		CSPString operator + ( const CSPWString& wstrString ) const;
		CSPString operator + ( const std::string& strString ) const;
#if !defined _GCC_
		CSPString operator + ( const std::wstring& wstrString ) const;
#endif
		CSPString operator + ( const CSPVariant& varValue ) const;
		CSPString operator + ( long double ldblNumber ) const;
		CSPString operator + ( double dblNumber ) const;
		CSPString operator + ( float fNumber ) const;
		CSPString operator + ( long lNumber ) const;
		CSPString operator + ( unsigned long ulNumber ) const;
		CSPString operator + ( int iNumber ) const;
		CSPString operator + ( unsigned int uiNumber ) const;
		CSPString operator + ( __int64 i64Number ) const;
		CSPString operator + ( unsigned __int64 ui64Number ) const;
		CSPString operator + ( bool bBool ) const;
		CSPString operator + ( const CSPDate& dDate );
		CSPString operator + ( const CSPDateTime& dtDateTime );
		CSPString operator + ( const CSPTime& tTime );

		bool operator == ( const char* pszString ) const;
		bool operator == ( const wchar_t* pwszString ) const;
		bool operator == ( const CSPString& strString ) const;
		bool operator == ( const CSPWString& wstrString ) const;
		bool operator == ( const std::string& strString ) const;
#if !defined _GCC_
		bool operator == ( const std::wstring& wstrString ) const;
#endif
		bool operator == ( const CSPVariant& varValue ) const;
		bool operator == ( long double ldblNumber ) const;
		bool operator == ( double dblNumber ) const;
		bool operator == ( float fNumber ) const;
		bool operator == ( long lNumber ) const;
		bool operator == ( unsigned long ulNumber ) const;
		bool operator == ( int iNumber ) const;
		bool operator == ( unsigned int uiNumber ) const;
		bool operator == ( __int64 i64Number ) const;
		bool operator == ( unsigned __int64 ui64Number ) const;
		bool operator == ( bool bBool ) const;

		bool operator != ( const char* pszString ) const;
		bool operator != ( const wchar_t* pwszString ) const;
		bool operator != ( const CSPString& strString ) const;
		bool operator != ( const CSPWString& wstrString ) const;
		bool operator != ( const std::string& strString ) const;
#if !defined _GCC_
		bool operator != ( const std::wstring& wstrString ) const;
#endif
		bool operator != ( const CSPVariant& varValue ) const;
		bool operator != ( long double ldblNumber ) const;
		bool operator != ( double dblNumber ) const;
		bool operator != ( float fNumber ) const;
		bool operator != ( long lNumber ) const;
		bool operator != ( unsigned long ulNumber ) const;
		bool operator != ( int iNumber ) const;
		bool operator != ( __int64 i64Number ) const;
		bool operator != ( unsigned int uiNumber ) const;
		bool operator != ( unsigned __int64 ui64Number ) const;
		bool operator != ( bool bBool ) const;

		bool operator > ( const CSPString& strString ) const;
		bool operator > ( const char* pszString ) const;
		bool operator >= ( const CSPString& strString ) const;
		bool operator >= ( const char* pszString ) const;
		bool operator <= ( const CSPString& strString ) const;
		bool operator <= ( const char* pszString ) const;
		bool operator < ( const CSPString& strString ) const;
		bool operator < ( const char* pszString ) const;

		operator const char* () const;

		static bool SetLocale( const CSPString& strLocale );

	protected:
		char* m_pszBuffer;
		unsigned long m_ulLength;
		unsigned long m_ulSize;
		char m_chEmpty;
};


CSPString CSPLIB_CLASS_EXPORT operator + ( const char* pszString, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( const wchar_t* pwszString, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( const std::string& strString, const CSPString& String );
#if !defined _GCC_
CSPString CSPLIB_CLASS_EXPORT operator + ( const std::wstring& wstrString, const CSPString& String );
#endif
CSPString CSPLIB_CLASS_EXPORT operator + ( const CSPVariant& varValue, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( long double ldblNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( double dblNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( float fNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( long lNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( unsigned long ulNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( int iNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( unsigned int uiNumber, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( __int64 i64Number, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( unsigned __int64 ui64Number, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( bool bBool, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( const CSPDate& dDate, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( const CSPDateTime& dtDateTime, const CSPString& String );
CSPString CSPLIB_CLASS_EXPORT operator + ( const CSPTime& tTime, const CSPString& String );

#endif 
