00001 #ifndef _MERCURY_STRING_H
00002 #define _MERCURY_STRING_H
00003
00005 class MString
00006 {
00007 public:
00008 MString();
00009 MString( int iPreAlloc );
00010 MString( const char sIn );
00011 MString( const char * sIn );
00012 MString( const char * sIn, int iSize );
00013 MString( const MString & rhs );
00014 ~MString();
00015
00016 const MString & operator = ( const MString & rhs );
00017 const MString & operator = ( const char * rhs );
00018 const MString operator + ( const MString & rhs ) const;
00019 const MString operator + ( const char * rhs ) const;
00020 const MString operator + ( const char rhs ) const;
00021 const MString & operator += ( const char * rhs );
00022 const MString & operator += ( const MString & rhs );
00023 const MString & operator += ( const char rhs );
00024
00025 bool operator == ( const MString & rhs );
00026 bool operator == ( const char * rhs );
00027 bool operator < ( const MString & rhs );
00028 bool operator > ( const MString & rhs );
00029
00030 operator const char * () const { return m_sCur; }
00031
00032 inline const char * c_str() const { return m_sCur; }
00033 inline unsigned long length() const { return m_iLen; }
00034 inline unsigned long size() const { return m_iLen; }
00035 inline bool empty() const { return m_iLen == 0; }
00036
00037 void append( const MString & app );
00038 void append( const char app );
00039 void append( const char * app );
00040 void append( const char * app, int len );
00041
00043 void append( const char app, int len );
00044
00045 void assign( const MString & app );
00046 void assign( const char * app );
00047 void assign( const char * app, int len );
00048
00049 int find( const MString & tofind, int start = 0 ) const;
00050 int rfind( const MString & tofind ) const;
00051 inline int find_last_of( const MString & tofind ) const { return rfind( tofind ); }
00052
00053 int find( const char * tofind,int start = 0 ) const;
00054 int find( const char tofind, int start = 0 ) const;
00055 int rfind( const char * tofind ) const;
00056 int rfind( const char tofind ) const;
00057 inline int find_last_of( const char * tofind ) const { return rfind( tofind ); }
00058
00059 const MString substr( int iStart ) const;
00060 const MString substr( int iStart, int iLength ) const;
00061
00062 int compare( const MString & cmp ) const;
00063 int compare( const char * cmp ) const;
00064
00065 int compare( int start, int len, const MString & cmp ) const;
00066 int compare( int start, int len, const char * cmp ) const;
00067
00068 unsigned int hash() const;
00069
00070 enum
00071 {
00072 npos = -1
00073 };
00074
00075 void resize( unsigned int size );
00076 private:
00077 char * m_sCur;
00078 unsigned int m_iLen;
00079 unsigned int m_iAlloc;
00080 friend bool operator < ( const MString & lhs, const MString & rhs );
00081 friend bool operator > ( const MString & lhs, const MString & rhs );
00082 };
00083
00084
00085
00086
00087
00088
00089 bool operator < ( const MString & lhs, const MString & rhs );
00090 bool operator > ( const MString & lhs, const MString & rhs );
00091 inline bool operator == ( const MString & lhs, const char * rhs ) { return lhs.compare( rhs ) == 0; }
00092 inline bool operator != ( const MString & lhs, const char * rhs ) { return lhs.compare( rhs ) != 0; }
00093
00094 MString operator + ( const char lhs, const MString & rhs );
00095 MString operator + ( const char * lhs, const MString & rhs );
00096
00097 #if defined(__GNUC__)
00098 #define PRINTF(a,b) __attribute__((format(__printf__,a,b)))
00099 #else
00100 #define PRINTF(a,b)
00101 #endif
00102
00103 MString ssprintf( const char *fmt, ...) PRINTF(1,2);
00104
00105 #endif
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133