Orb/Doxygen/qtools/qgstring.h
changeset 3 d8fccb2cd802
parent 0 42188c7ea2d9
equal deleted inserted replaced
2:932c358ece3e 3:d8fccb2cd802
       
     1 #ifndef QGSTRING_H
       
     2 #define QGSTRING_H
       
     3 
       
     4 #include <stdlib.h>
       
     5 #include <string.h>
       
     6 
       
     7 #if defined(_OS_SUN_) && defined(_CC_GNU_)
       
     8 #include <strings.h>
       
     9 #endif
       
    10 
       
    11 #include "qcstring.h"
       
    12 
       
    13 /*****************************************************************************
       
    14   Fixes and workarounds for some platforms
       
    15  *****************************************************************************/
       
    16 
       
    17 /** This is an alternative implementation of QCString. 
       
    18  */
       
    19 class QGString 
       
    20 {
       
    21   public:
       
    22     QGString(); // make null string
       
    23     QGString(uint size); 
       
    24     QGString( const QGString &s );
       
    25     QGString( const char *str );
       
    26    ~QGString() ;
       
    27 
       
    28     bool resize( uint newlen );
       
    29 
       
    30     QGString    &operator=( const QGString &s );
       
    31     QGString    &operator=( const char *str );
       
    32     QGString    &operator+=( const QGString &s );
       
    33     QGString    &operator+=( const char *str );
       
    34     QGString    &operator+=( char c );
       
    35 
       
    36     bool        isNull()        const { return m_data==0; }
       
    37     bool	isEmpty()	const { return m_len==0; }
       
    38     uint	length()	const { return m_len; }
       
    39     uint        size()          const { return m_memSize; }
       
    40     char *      data()          const { return m_data; }
       
    41     bool	truncate( uint pos )  { return resize(pos+1); }
       
    42         operator const char *() const { return (const char *)data(); }
       
    43     char &at( uint index ) const      { return m_data[index]; }
       
    44     char &operator[]( int i ) const   { return at(i); }
       
    45     
       
    46   private:
       
    47     char *      m_data;
       
    48     uint        m_len;
       
    49     uint        m_memSize;
       
    50 };
       
    51 
       
    52 /*****************************************************************************
       
    53   QGString non-member operators
       
    54  *****************************************************************************/
       
    55 
       
    56 Q_EXPORT inline bool operator==( const QGString &s1, const QGString &s2 )
       
    57 { return qstrcmp(s1.data(),s2.data()) == 0; }
       
    58 
       
    59 Q_EXPORT inline bool operator==( const QGString &s1, const char *s2 )
       
    60 { return qstrcmp(s1.data(),s2) == 0; }
       
    61 
       
    62 Q_EXPORT inline bool operator==( const char *s1, const QGString &s2 )
       
    63 { return qstrcmp(s1,s2.data()) == 0; }
       
    64 
       
    65 Q_EXPORT inline bool operator!=( const QGString &s1, const QGString &s2 )
       
    66 { return qstrcmp(s1.data(),s2.data()) != 0; }
       
    67 
       
    68 Q_EXPORT inline bool operator!=( const QGString &s1, const char *s2 )
       
    69 { return qstrcmp(s1.data(),s2) != 0; }
       
    70 
       
    71 Q_EXPORT inline bool operator!=( const char *s1, const QGString &s2 )
       
    72 { return qstrcmp(s1,s2.data()) != 0; }
       
    73 
       
    74 Q_EXPORT inline bool operator<( const QGString &s1, const QGString& s2 )
       
    75 { return qstrcmp(s1.data(),s2.data()) < 0; }
       
    76 
       
    77 Q_EXPORT inline bool operator<( const QGString &s1, const char *s2 )
       
    78 { return qstrcmp(s1.data(),s2) < 0; }
       
    79 
       
    80 Q_EXPORT inline bool operator<( const char *s1, const QGString &s2 )
       
    81 { return qstrcmp(s1,s2.data()) < 0; }
       
    82 
       
    83 Q_EXPORT inline bool operator<=( const QGString &s1, const char *s2 )
       
    84 { return qstrcmp(s1.data(),s2) <= 0; }
       
    85 
       
    86 Q_EXPORT inline bool operator<=( const char *s1, const QGString &s2 )
       
    87 { return qstrcmp(s1,s2.data()) <= 0; }
       
    88 
       
    89 Q_EXPORT inline bool operator>( const QGString &s1, const char *s2 )
       
    90 { return qstrcmp(s1.data(),s2) > 0; }
       
    91 
       
    92 Q_EXPORT inline bool operator>( const char *s1, const QGString &s2 )
       
    93 { return qstrcmp(s1,s2.data()) > 0; }
       
    94 
       
    95 Q_EXPORT inline bool operator>=( const QGString &s1, const char *s2 )
       
    96 { return qstrcmp(s1.data(),s2) >= 0; }
       
    97 
       
    98 Q_EXPORT inline bool operator>=( const char *s1, const QGString &s2 )
       
    99 { return qstrcmp(s1,s2.data()) >= 0; }
       
   100 
       
   101 Q_EXPORT inline QGString operator+( const QGString &s1, const QGString &s2 )
       
   102 {
       
   103     QGString tmp( s1.data() );
       
   104     tmp += s2;
       
   105     return tmp;
       
   106 }
       
   107 
       
   108 Q_EXPORT inline QGString operator+( const QGString &s1, const char *s2 )
       
   109 {
       
   110     QGString tmp( s1.data() );
       
   111     tmp += s2;
       
   112     return tmp;
       
   113 }
       
   114 
       
   115 Q_EXPORT inline QGString operator+( const char *s1, const QGString &s2 )
       
   116 {
       
   117     QGString tmp( s1 );
       
   118     tmp += s2;
       
   119     return tmp;
       
   120 }
       
   121 
       
   122 Q_EXPORT inline QGString operator+( const QGString &s1, char c2 )
       
   123 {
       
   124     QGString tmp( s1.data() );
       
   125     tmp += c2;
       
   126     return tmp;
       
   127 }
       
   128 
       
   129 Q_EXPORT inline QGString operator+( char c1, const QGString &s2 )
       
   130 {
       
   131     QGString tmp;
       
   132     tmp += c1;
       
   133     tmp += s2;
       
   134     return tmp;
       
   135 }
       
   136 
       
   137 #endif // QGSTRING_H