MercuryString.h

Go to the documentation of this file.
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 /* //Keep around incase we need to debug a little and use our old string
00085 #include "StdString.h"
00086 typedef StdString::CStdString MString;
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  * Copyright (c) 2006, Charles Lohr
00109  * All rights reserved.
00110  *
00111  * Redistribution and use in source and binary forms, with or
00112  * without modification, are permitted provided that the following
00113  * conditions are met:
00114  *  -   Redistributions of source code must retain the above
00115  *      copyright notice, this list of conditions and the following disclaimer.
00116  *  -   Redistributions in binary form must reproduce the above copyright
00117  *      notice, this list of conditions and the following disclaimer in
00118  *      the documentation and/or other materials provided with the distribution.
00119  *  -   Neither the name of the Mercury Engine nor the names of its
00120  *      contributors may be used to endorse or promote products derived from
00121  *      this software without specific prior written permission.
00122  *
00123  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00124  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00125  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00126  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00127  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00128  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00129  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00130  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00131  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00132  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00133  */

Hosted by SourceForge.net Logo