ISLEman
qgstring.h
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 
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  bool enlarge( uint newlen );
30  void setLen( uint newlen );
31 
32  QGString &operator=( const QGString &s );
33  QGString &operator=( const char *str );
34  QGString &operator+=( const QGString &s );
35  QGString &operator+=( const char *str );
36  QGString &operator+=( char c );
37 
38  bool isNull() const { return m_data==0; }
39  bool isEmpty() const { return m_len==0; }
40  uint length() const { return m_len; }
41  uint size() const { return m_memSize; }
42  char * data() const { return m_data; }
43  bool truncate( uint pos ) { return resize(pos+1); }
44  operator const char *() const { return (const char *)data(); }
45  char &at( uint index ) const { return m_data[index]; }
46  char &operator[]( int i ) const { return at(i); }
47 
48  private:
49  char * m_data;
50  uint m_len;
51  uint m_memSize;
52 };
53 
54 /*****************************************************************************
55  QGString non-member operators
56  *****************************************************************************/
57 
58 Q_EXPORT inline bool operator==( const QGString &s1, const QGString &s2 )
59 { return qstrcmp(s1.data(),s2.data()) == 0; }
60 
61 Q_EXPORT inline bool operator==( const QGString &s1, const char *s2 )
62 { return qstrcmp(s1.data(),s2) == 0; }
63 
64 Q_EXPORT inline bool operator==( const char *s1, const QGString &s2 )
65 { return qstrcmp(s1,s2.data()) == 0; }
66 
67 Q_EXPORT inline bool operator!=( const QGString &s1, const QGString &s2 )
68 { return qstrcmp(s1.data(),s2.data()) != 0; }
69 
70 Q_EXPORT inline bool operator!=( const QGString &s1, const char *s2 )
71 { return qstrcmp(s1.data(),s2) != 0; }
72 
73 Q_EXPORT inline bool operator!=( const char *s1, const QGString &s2 )
74 { return qstrcmp(s1,s2.data()) != 0; }
75 
76 Q_EXPORT inline bool operator<( const QGString &s1, const QGString& s2 )
77 { return qstrcmp(s1.data(),s2.data()) < 0; }
78 
79 Q_EXPORT inline bool operator<( const QGString &s1, const char *s2 )
80 { return qstrcmp(s1.data(),s2) < 0; }
81 
82 Q_EXPORT inline bool operator<( const char *s1, const QGString &s2 )
83 { return qstrcmp(s1,s2.data()) < 0; }
84 
85 Q_EXPORT inline bool operator<=( const QGString &s1, const char *s2 )
86 { return qstrcmp(s1.data(),s2) <= 0; }
87 
88 Q_EXPORT inline bool operator<=( const char *s1, const QGString &s2 )
89 { return qstrcmp(s1,s2.data()) <= 0; }
90 
91 Q_EXPORT inline bool operator>( const QGString &s1, const char *s2 )
92 { return qstrcmp(s1.data(),s2) > 0; }
93 
94 Q_EXPORT inline bool operator>( const char *s1, const QGString &s2 )
95 { return qstrcmp(s1,s2.data()) > 0; }
96 
97 Q_EXPORT inline bool operator>=( const QGString &s1, const char *s2 )
98 { return qstrcmp(s1.data(),s2) >= 0; }
99 
100 Q_EXPORT inline bool operator>=( const char *s1, const QGString &s2 )
101 { return qstrcmp(s1,s2.data()) >= 0; }
102 
103 Q_EXPORT inline QGString operator+( const QGString &s1, const QGString &s2 )
104 {
105  QGString tmp( s1.data() );
106  tmp += s2;
107  return tmp;
108 }
109 
110 Q_EXPORT inline QGString operator+( const QGString &s1, const char *s2 )
111 {
112  QGString tmp( s1.data() );
113  tmp += s2;
114  return tmp;
115 }
116 
117 Q_EXPORT inline QGString operator+( const char *s1, const QGString &s2 )
118 {
119  QGString tmp( s1 );
120  tmp += s2;
121  return tmp;
122 }
123 
124 Q_EXPORT inline QGString operator+( const QGString &s1, char c2 )
125 {
126  QGString tmp( s1.data() );
127  tmp += c2;
128  return tmp;
129 }
130 
131 Q_EXPORT inline QGString operator+( char c1, const QGString &s2 )
132 {
133  QGString tmp;
134  tmp += c1;
135  tmp += s2;
136  return tmp;
137 }
138 
139 #endif // QGSTRING_H
This is an alternative implementation of QCString.
Definition: qgstring.h:19