summaryrefslogtreecommitdiffstats
path: root/qtools/qgstring.h
blob: 0af1045e0822a984e8bb1825007b286716c1fe19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef QGSTRING_H
#define QGSTRING_H

#include <stdlib.h>
#include <string.h>

#if defined(_OS_SUN_) && defined(_CC_GNU_)
#include <strings.h>
#endif

#include "qcstring.h"

/*****************************************************************************
  Fixes and workarounds for some platforms
 *****************************************************************************/

/** This is an alternative implementation of QCString. 
 */
class QGString 
{
  public:
    QGString(); // make null string
    QGString(uint size); 
    QGString( const QGString &s );
    QGString( const char *str );
   ~QGString() ;

    bool resize( uint newlen );
    bool enlarge( uint newlen );
    void setLen( uint newlen );

    QGString    &operator=( const QGString &s );
    QGString    &operator=( const char *str );
    QGString    &operator+=( const QGString &s );
    QGString    &operator+=( const char *str );
    QGString    &operator+=( char c );

    bool        isNull()        const { return m_data==0; }
    bool	isEmpty()	const { return m_len==0; }
    uint	length()	const { return m_len; }
    uint        size()          const { return m_memSize; }
    char *      data()          const { return m_data; }
    bool	truncate( uint pos )  { return resize(pos+1); }
        operator const char *() const { return (const char *)data(); }
    char &at( uint index ) const      { return m_data[index]; }
    char &operator[]( uint i ) const  { return at(i); }
    
  private:
    char *      m_data;
    uint        m_len;
    uint        m_memSize;
};

/*****************************************************************************
  QGString non-member operators
 *****************************************************************************/

Q_EXPORT inline bool operator==( const QGString &s1, const QGString &s2 )
{ return qstrcmp(s1.data(),s2.data()) == 0; }

Q_EXPORT inline bool operator==( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) == 0; }

Q_EXPORT inline bool operator==( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) == 0; }

Q_EXPORT inline bool operator!=( const QGString &s1, const QGString &s2 )
{ return qstrcmp(s1.data(),s2.data()) != 0; }

Q_EXPORT inline bool operator!=( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) != 0; }

Q_EXPORT inline bool operator!=( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) != 0; }

Q_EXPORT inline bool operator<( const QGString &s1, const QGString& s2 )
{ return qstrcmp(s1.data(),s2.data()) < 0; }

Q_EXPORT inline bool operator<( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) < 0; }

Q_EXPORT inline bool operator<( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) < 0; }

Q_EXPORT inline bool operator<=( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) <= 0; }

Q_EXPORT inline bool operator<=( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) <= 0; }

Q_EXPORT inline bool operator>( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) > 0; }

Q_EXPORT inline bool operator>( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) > 0; }

Q_EXPORT inline bool operator>=( const QGString &s1, const char *s2 )
{ return qstrcmp(s1.data(),s2) >= 0; }

Q_EXPORT inline bool operator>=( const char *s1, const QGString &s2 )
{ return qstrcmp(s1,s2.data()) >= 0; }

Q_EXPORT inline QGString operator+( const QGString &s1, const QGString &s2 )
{
    QGString tmp( s1.data() );
    tmp += s2;
    return tmp;
}

Q_EXPORT inline QGString operator+( const QGString &s1, const char *s2 )
{
    QGString tmp( s1.data() );
    tmp += s2;
    return tmp;
}

Q_EXPORT inline QGString operator+( const char *s1, const QGString &s2 )
{
    QGString tmp( s1 );
    tmp += s2;
    return tmp;
}

Q_EXPORT inline QGString operator+( const QGString &s1, char c2 )
{
    QGString tmp( s1.data() );
    tmp += c2;
    return tmp;
}

Q_EXPORT inline QGString operator+( char c1, const QGString &s2 )
{
    QGString tmp;
    tmp += c1;
    tmp += s2;
    return tmp;
}

#endif // QGSTRING_H