1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt3Support module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
45 #include <QtCore/qbytearray.h>
51 QT_MODULE(Qt3SupportLight
)
53 /*****************************************************************************
55 *****************************************************************************/
59 class Q_COMPAT_EXPORT Q3CString
: public QByteArray
63 Q3CString(int size
) : QByteArray(size
, '\0') {}
64 Q3CString(const Q3CString
&s
) : QByteArray(s
) {}
65 Q3CString(const QByteArray
&ba
) : QByteArray(ba
) {}
66 Q3CString(const char *str
) : QByteArray(str
) {}
67 Q3CString(const char *str
, uint maxlen
) : QByteArray(str
, qMin(qstrlen(str
), maxlen
- 1)) {}
69 Q3CString
&operator=(const Q3CString
&s
) {
70 QByteArray::operator=(s
); return *this;
72 Q3CString
&operator=(const char *str
) {
73 QByteArray::operator=(str
); return *this;
75 Q3CString
&operator=(const QByteArray
&ba
) {
76 QByteArray::operator=(ba
); return *this;
79 Q3CString
copy() const { return *this; }
80 Q3CString
&sprintf(const char *format
, ...);
82 Q3CString
left(uint len
) const { return QByteArray::left(len
); }
83 Q3CString
right(uint len
) const { return QByteArray::right(len
); }
84 Q3CString
mid(uint index
, uint len
=0xffffffff) const { return QByteArray::mid(index
, len
); }
86 Q3CString
leftJustify(uint width
, char fill
=' ', bool trunc
=false)const;
87 Q3CString
rightJustify(uint width
, char fill
=' ',bool trunc
=false)const;
89 Q3CString
lower() const { return QByteArray::toLower(); }
90 Q3CString
upper() const { return QByteArray::toUpper(); }
92 Q3CString
stripWhiteSpace() const { return QByteArray::trimmed(); }
93 Q3CString
simplifyWhiteSpace() const { return QByteArray::simplified(); }
95 Q3CString
&insert(uint index
, const char *c
) { QByteArray::insert(index
, c
); return *this; }
96 Q3CString
&insert(uint index
, char c
) { QByteArray::insert(index
, c
); return *this; }
97 Q3CString
&append(const char *c
) { QByteArray::append(c
); return *this; }
98 Q3CString
&prepend(const char *c
) { QByteArray::prepend(c
); return *this; }
99 Q3CString
&remove(uint index
, uint len
) { QByteArray::remove(index
, len
); return *this; }
100 Q3CString
&replace(uint index
, uint len
, const char *c
)
101 { QByteArray::replace(index
, len
, c
); return *this; }
102 Q3CString
&replace(char c
, const Q3CString
&after
) { return replace(c
, after
.constData()); }
103 Q3CString
&replace(char c
, const char *after
) { QByteArray::replace(c
, after
); return *this; }
104 Q3CString
&replace(const Q3CString
&b
, const Q3CString
&a
)
105 { return replace(b
.constData(), a
.constData()); }
106 Q3CString
&replace(const char *b
, const char *a
) { QByteArray::replace(b
, a
); return *this; }
107 Q3CString
&replace(char b
, char a
) { QByteArray::replace(b
, a
); return *this; }
109 short toShort(bool *ok
=0) const;
110 ushort
toUShort(bool *ok
=0) const;
111 int toInt(bool *ok
=0) const;
112 uint
toUInt(bool *ok
=0) const;
113 long toLong(bool *ok
=0) const;
114 ulong
toULong(bool *ok
=0) const;
115 float toFloat(bool *ok
=0) const;
116 double toDouble(bool *ok
=0) const;
118 Q3CString
&setStr(const char *s
) { *this = s
; return *this; }
119 Q3CString
&setNum(short);
120 Q3CString
&setNum(ushort
);
121 Q3CString
&setNum(int);
122 Q3CString
&setNum(uint
);
123 Q3CString
&setNum(long);
124 Q3CString
&setNum(ulong
);
125 Q3CString
&setNum(float, char f
='g', int prec
=6);
126 Q3CString
&setNum(double, char f
='g', int prec
=6);
128 bool setExpand(uint index
, char c
);
133 /*****************************************************************************
134 Q3CString stream functions
135 *****************************************************************************/
136 #ifndef QT_NO_DATASTREAM
137 Q_COMPAT_EXPORT QDataStream
&operator<<(QDataStream
&d
, const Q3CString
&s
);
138 Q_COMPAT_EXPORT QDataStream
&operator>>(QDataStream
&d
, Q3CString
&s
);
141 /*****************************************************************************
142 Q3CString inline functions
143 *****************************************************************************/
145 inline Q3CString
&Q3CString::setNum(short n
)
146 { return setNum(long(n
)); }
148 inline Q3CString
&Q3CString::setNum(ushort n
)
149 { return setNum(ulong(n
)); }
151 inline Q3CString
&Q3CString::setNum(int n
)
152 { return setNum(long(n
)); }
154 inline Q3CString
&Q3CString::setNum(uint n
)
155 { return setNum(ulong(n
)); }
157 inline Q3CString
&Q3CString::setNum(float n
, char f
, int prec
)
158 { return setNum(double(n
),f
,prec
); }
160 /*****************************************************************************
161 Q3CString non-member operators
162 *****************************************************************************/
164 Q_COMPAT_EXPORT
inline bool operator==(const Q3CString
&s1
, const Q3CString
&s2
)
165 { return qstrcmp(s1
, s2
) == 0; }
167 Q_COMPAT_EXPORT
inline bool operator==(const Q3CString
&s1
, const char *s2
)
168 { return qstrcmp(s1
, s2
) == 0; }
170 Q_COMPAT_EXPORT
inline bool operator==(const char *s1
, const Q3CString
&s2
)
171 { return qstrcmp(s1
, s2
) == 0; }
173 Q_COMPAT_EXPORT
inline bool operator!=(const Q3CString
&s1
, const Q3CString
&s2
)
174 { return qstrcmp(s1
, s2
) != 0; }
176 Q_COMPAT_EXPORT
inline bool operator!=(const Q3CString
&s1
, const char *s2
)
177 { return qstrcmp(s1
, s2
) != 0; }
179 Q_COMPAT_EXPORT
inline bool operator!=(const char *s1
, const Q3CString
&s2
)
180 { return qstrcmp(s1
, s2
) != 0; }
182 Q_COMPAT_EXPORT
inline bool operator<(const Q3CString
&s1
, const Q3CString
& s2
)
183 { return qstrcmp(s1
, s2
) < 0; }
185 Q_COMPAT_EXPORT
inline bool operator<(const Q3CString
&s1
, const char *s2
)
186 { return qstrcmp(s1
, s2
) < 0; }
188 Q_COMPAT_EXPORT
inline bool operator<(const char *s1
, const Q3CString
&s2
)
189 { return qstrcmp(s1
, s2
) < 0; }
191 Q_COMPAT_EXPORT
inline bool operator<=(const Q3CString
&s1
, const Q3CString
&s2
)
192 { return qstrcmp(s1
, s2
) <= 0; }
194 Q_COMPAT_EXPORT
inline bool operator<=(const Q3CString
&s1
, const char *s2
)
195 { return qstrcmp(s1
, s2
) <= 0; }
197 Q_COMPAT_EXPORT
inline bool operator<=(const char *s1
, const Q3CString
&s2
)
198 { return qstrcmp(s1
, s2
) <= 0; }
200 Q_COMPAT_EXPORT
inline bool operator>(const Q3CString
&s1
, const Q3CString
&s2
)
201 { return qstrcmp(s1
, s2
) > 0; }
203 Q_COMPAT_EXPORT
inline bool operator>(const Q3CString
&s1
, const char *s2
)
204 { return qstrcmp(s1
, s2
) > 0; }
206 Q_COMPAT_EXPORT
inline bool operator>(const char *s1
, const Q3CString
&s2
)
207 { return qstrcmp(s1
, s2
) > 0; }
209 Q_COMPAT_EXPORT
inline bool operator>=(const Q3CString
&s1
, const Q3CString
& s2
)
210 { return qstrcmp(s1
, s2
) >= 0; }
212 Q_COMPAT_EXPORT
inline bool operator>=(const Q3CString
&s1
, const char *s2
)
213 { return qstrcmp(s1
, s2
) >= 0; }
215 Q_COMPAT_EXPORT
inline bool operator>=(const char *s1
, const Q3CString
&s2
)
216 { return qstrcmp(s1
, s2
) >= 0; }
218 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const Q3CString
&s1
,
225 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const Q3CString
&s1
,
226 const QByteArray
&s2
)
232 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const QByteArray
&s1
,
240 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const Q3CString
&s1
, const char *s2
)
247 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const char *s1
, const Q3CString
&s2
)
254 Q_COMPAT_EXPORT
inline const Q3CString
operator+(const Q3CString
&s1
, char c2
)
261 Q_COMPAT_EXPORT
inline const Q3CString
operator+(char c1
, const Q3CString
&s2
)
273 #endif // Q3CSTRING_H