qgstring.h
Go to the documentation of this file.
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  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;
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
char & at(uint index) const
Definition: qgstring.h:45
char * data() const
Definition: qgstring.h:42
uint length() const
Definition: qgstring.h:40
QGString()
Definition: qgstring.cpp:27
Q_EXPORT bool operator<=(const QGString &s1, const char *s2)
Definition: qgstring.h:85
Q_EXPORT bool operator>(const QGString &s1, const char *s2)
Definition: qgstring.h:91
bool resize(uint newlen)
Definition: qgstring.cpp:96
uint m_memSize
Definition: qgstring.h:51
QGString & operator+=(const QGString &s)
Definition: qgstring.cpp:203
Q_EXPORT bool operator!=(const QGString &s1, const QGString &s2)
Definition: qgstring.h:67
bool truncate(uint pos)
Definition: qgstring.h:43
Q_EXPORT QGString operator+(const QGString &s1, const QGString &s2)
Definition: qgstring.h:103
Q_EXPORT bool operator>=(const QGString &s1, const char *s2)
Definition: qgstring.h:97
uint m_len
Definition: qgstring.h:50
string tmp
Definition: languages.py:63
uint size() const
Definition: qgstring.h:41
char & operator[](int i) const
Definition: qgstring.h:46
Q_EXPORT bool operator==(const QGString &s1, const QGString &s2)
Definition: qgstring.h:58
~QGString()
Definition: qgstring.cpp:89
bool isEmpty() const
Definition: qgstring.h:39
void setLen(uint newlen)
Definition: qgstring.cpp:156
bool enlarge(uint newlen)
Definition: qgstring.cpp:127
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
unsigned uint
Definition: qglobal.h:351
char * m_data
Definition: qgstring.h:49
bool isNull() const
Definition: qgstring.h:38
static QCString * s
Definition: config.cpp:1042
#define Q_EXPORT
Definition: qglobal.h:468
QGString & operator=(const QGString &s)
Definition: qgstring.cpp:161
static QCString str
Q_EXPORT bool operator<(const QGString &s1, const QGString &s2)
Definition: qgstring.h:76