//----------------------- CSPWString.h ------------------------

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


#ifndef _CSPWSTRING
#define _CSPWSTRING

#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 CSPString;
class CSPLIB_CLASS_EXPORT CSPVariant;

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

		void HTMLDecode();
		void HTMLEncode();
		wchar_t GetChar( unsigned long ulIndex )  const;
		void SetChar( unsigned long ulPos, wchar_t wchChar);
		void Add( const wchar_t* pwszString, unsigned long length = 0 );
		unsigned long Length() const;
		void SetSize( unsigned long ulNewSize );
		void Empty();
		void Clear();
		void UpperCase();
		void LowerCase();
		unsigned long Find( const wchar_t* pwszSubString, unsigned long ulStartIndex = 0 ) const;
		unsigned long Find( const CSPWString& wstrSubString, unsigned long ulStartIndex = 0 ) const;
		long CompareNoCase( const CSPWString& wstrString ) const;
		long CompareNoCase( const wchar_t* pwszString ) const;
		CSPWString Mid( unsigned long ulStartPos, unsigned long ulLength ) const;
		int GetIntVal() const;
		__int64 GetInt64Val() const;
		double GetDoubleVal() const;
		unsigned long Replace( const CSPWString& wstrFind, const CSPWString& wstrReplace, unsigned long ulFirst = 0 );
		const wchar_t* GetPtr() const;

		CSPWString();
		virtual ~CSPWString();

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


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

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

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

		bool operator == ( const wchar_t* pwszString ) const;
		bool operator == ( const char* pszString ) const;
		bool operator == ( const CSPWString& wstrString ) const;
		bool operator == ( const CSPString& strString ) const;
#if !defined _GCC_
		bool operator == ( const std::wstring& wstrString ) const;
#endif
		bool operator == ( const std::string& strString ) const;
		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 wchar_t* pwszString ) const;
		bool operator != ( const char* pszString ) const;
		bool operator != ( const CSPWString& wstrString ) const;
		bool operator != ( const CSPString& strString ) const;
#if !defined _GCC_
		bool operator != ( const std::wstring& wstrString ) const;
#endif
		bool operator != ( const std::string& strString ) const;
		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 CSPWString& wstrString ) const;
		bool operator > ( const wchar_t* pwszString ) const;
		bool operator >= ( const CSPWString& wstrString ) const;
		bool operator >= ( const wchar_t* pwszString ) const;
		bool operator <= ( const CSPWString& wstrString ) const;
		bool operator <= ( const wchar_t* pwszString ) const;
		bool operator < ( const CSPWString& wstrString ) const;
		bool operator < ( const wchar_t* pwszString ) const;

		operator const wchar_t* () const;

		static bool SetLocale( const CSPWString& strLocale );

	protected:
		wchar_t* m_pwszBuffer;
		unsigned long m_ulLength;
		unsigned long m_ulSize;
		wchar_t m_wchEmpty;
};


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

#endif 
