| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 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.
|
|---|
| 23 | **
|
|---|
| 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.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef Q3CSTRING_H
|
|---|
| 43 | #define Q3CSTRING_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qbytearray.h>
|
|---|
| 46 |
|
|---|
| 47 | QT_BEGIN_HEADER
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | QT_MODULE(Qt3SupportLight)
|
|---|
| 52 |
|
|---|
| 53 | /*****************************************************************************
|
|---|
| 54 | QCString class
|
|---|
| 55 | *****************************************************************************/
|
|---|
| 56 |
|
|---|
| 57 | class QRegExp;
|
|---|
| 58 |
|
|---|
| 59 | class Q_COMPAT_EXPORT Q3CString : public QByteArray
|
|---|
| 60 | {
|
|---|
| 61 | public:
|
|---|
| 62 | Q3CString() {}
|
|---|
| 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)) {}
|
|---|
| 68 |
|
|---|
| 69 | Q3CString &operator=(const Q3CString &s) {
|
|---|
| 70 | QByteArray::operator=(s); return *this;
|
|---|
| 71 | }
|
|---|
| 72 | Q3CString &operator=(const char *str) {
|
|---|
| 73 | QByteArray::operator=(str); return *this;
|
|---|
| 74 | }
|
|---|
| 75 | Q3CString &operator=(const QByteArray &ba) {
|
|---|
| 76 | QByteArray::operator=(ba); return *this;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | Q3CString copy() const { return *this; }
|
|---|
| 80 | Q3CString &sprintf(const char *format, ...);
|
|---|
| 81 |
|
|---|
| 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); }
|
|---|
| 85 |
|
|---|
| 86 | Q3CString leftJustify(uint width, char fill=' ', bool trunc=false)const;
|
|---|
| 87 | Q3CString rightJustify(uint width, char fill=' ',bool trunc=false)const;
|
|---|
| 88 |
|
|---|
| 89 | Q3CString lower() const { return QByteArray::toLower(); }
|
|---|
| 90 | Q3CString upper() const { return QByteArray::toUpper(); }
|
|---|
| 91 |
|
|---|
| 92 | Q3CString stripWhiteSpace() const { return QByteArray::trimmed(); }
|
|---|
| 93 | Q3CString simplifyWhiteSpace() const { return QByteArray::simplified(); }
|
|---|
| 94 |
|
|---|
| 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; }
|
|---|
| 108 |
|
|---|
| 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;
|
|---|
| 117 |
|
|---|
| 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);
|
|---|
| 127 |
|
|---|
| 128 | bool setExpand(uint index, char c);
|
|---|
| 129 |
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 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);
|
|---|
| 139 | #endif
|
|---|
| 140 |
|
|---|
| 141 | /*****************************************************************************
|
|---|
| 142 | Q3CString inline functions
|
|---|
| 143 | *****************************************************************************/
|
|---|
| 144 |
|
|---|
| 145 | inline Q3CString &Q3CString::setNum(short n)
|
|---|
| 146 | { return setNum(long(n)); }
|
|---|
| 147 |
|
|---|
| 148 | inline Q3CString &Q3CString::setNum(ushort n)
|
|---|
| 149 | { return setNum(ulong(n)); }
|
|---|
| 150 |
|
|---|
| 151 | inline Q3CString &Q3CString::setNum(int n)
|
|---|
| 152 | { return setNum(long(n)); }
|
|---|
| 153 |
|
|---|
| 154 | inline Q3CString &Q3CString::setNum(uint n)
|
|---|
| 155 | { return setNum(ulong(n)); }
|
|---|
| 156 |
|
|---|
| 157 | inline Q3CString &Q3CString::setNum(float n, char f, int prec)
|
|---|
| 158 | { return setNum(double(n),f,prec); }
|
|---|
| 159 |
|
|---|
| 160 | /*****************************************************************************
|
|---|
| 161 | Q3CString non-member operators
|
|---|
| 162 | *****************************************************************************/
|
|---|
| 163 |
|
|---|
| 164 | Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const Q3CString &s2)
|
|---|
| 165 | { return qstrcmp(s1, s2) == 0; }
|
|---|
| 166 |
|
|---|
| 167 | Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const char *s2)
|
|---|
| 168 | { return qstrcmp(s1, s2) == 0; }
|
|---|
| 169 |
|
|---|
| 170 | Q_COMPAT_EXPORT inline bool operator==(const char *s1, const Q3CString &s2)
|
|---|
| 171 | { return qstrcmp(s1, s2) == 0; }
|
|---|
| 172 |
|
|---|
| 173 | Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const Q3CString &s2)
|
|---|
| 174 | { return qstrcmp(s1, s2) != 0; }
|
|---|
| 175 |
|
|---|
| 176 | Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const char *s2)
|
|---|
| 177 | { return qstrcmp(s1, s2) != 0; }
|
|---|
| 178 |
|
|---|
| 179 | Q_COMPAT_EXPORT inline bool operator!=(const char *s1, const Q3CString &s2)
|
|---|
| 180 | { return qstrcmp(s1, s2) != 0; }
|
|---|
| 181 |
|
|---|
| 182 | Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const Q3CString& s2)
|
|---|
| 183 | { return qstrcmp(s1, s2) < 0; }
|
|---|
| 184 |
|
|---|
| 185 | Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const char *s2)
|
|---|
| 186 | { return qstrcmp(s1, s2) < 0; }
|
|---|
| 187 |
|
|---|
| 188 | Q_COMPAT_EXPORT inline bool operator<(const char *s1, const Q3CString &s2)
|
|---|
| 189 | { return qstrcmp(s1, s2) < 0; }
|
|---|
| 190 |
|
|---|
| 191 | Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const Q3CString &s2)
|
|---|
| 192 | { return qstrcmp(s1, s2) <= 0; }
|
|---|
| 193 |
|
|---|
| 194 | Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const char *s2)
|
|---|
| 195 | { return qstrcmp(s1, s2) <= 0; }
|
|---|
| 196 |
|
|---|
| 197 | Q_COMPAT_EXPORT inline bool operator<=(const char *s1, const Q3CString &s2)
|
|---|
| 198 | { return qstrcmp(s1, s2) <= 0; }
|
|---|
| 199 |
|
|---|
| 200 | Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const Q3CString &s2)
|
|---|
| 201 | { return qstrcmp(s1, s2) > 0; }
|
|---|
| 202 |
|
|---|
| 203 | Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const char *s2)
|
|---|
| 204 | { return qstrcmp(s1, s2) > 0; }
|
|---|
| 205 |
|
|---|
| 206 | Q_COMPAT_EXPORT inline bool operator>(const char *s1, const Q3CString &s2)
|
|---|
| 207 | { return qstrcmp(s1, s2) > 0; }
|
|---|
| 208 |
|
|---|
| 209 | Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const Q3CString& s2)
|
|---|
| 210 | { return qstrcmp(s1, s2) >= 0; }
|
|---|
| 211 |
|
|---|
| 212 | Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const char *s2)
|
|---|
| 213 | { return qstrcmp(s1, s2) >= 0; }
|
|---|
| 214 |
|
|---|
| 215 | Q_COMPAT_EXPORT inline bool operator>=(const char *s1, const Q3CString &s2)
|
|---|
| 216 | { return qstrcmp(s1, s2) >= 0; }
|
|---|
| 217 |
|
|---|
| 218 | Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
|
|---|
| 219 | const Q3CString &s2)
|
|---|
| 220 | {
|
|---|
| 221 | Q3CString tmp(s1);
|
|---|
| 222 | tmp += s2;
|
|---|
| 223 | return tmp;
|
|---|
| 224 | }
|
|---|
| 225 | Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
|
|---|
| 226 | const QByteArray &s2)
|
|---|
| 227 | {
|
|---|
| 228 | QByteArray tmp(s1);
|
|---|
| 229 | tmp += s2;
|
|---|
| 230 | return tmp;
|
|---|
| 231 | }
|
|---|
| 232 | Q_COMPAT_EXPORT inline const Q3CString operator+(const QByteArray &s1,
|
|---|
| 233 | const Q3CString &s2)
|
|---|
| 234 | {
|
|---|
| 235 | QByteArray tmp(s1);
|
|---|
| 236 | tmp += s2;
|
|---|
| 237 | return tmp;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, const char *s2)
|
|---|
| 241 | {
|
|---|
| 242 | Q3CString tmp(s1);
|
|---|
| 243 | tmp += s2;
|
|---|
| 244 | return tmp;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | Q_COMPAT_EXPORT inline const Q3CString operator+(const char *s1, const Q3CString &s2)
|
|---|
| 248 | {
|
|---|
| 249 | Q3CString tmp(s1);
|
|---|
| 250 | tmp += s2;
|
|---|
| 251 | return tmp;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, char c2)
|
|---|
| 255 | {
|
|---|
| 256 | Q3CString tmp(s1);
|
|---|
| 257 | tmp += c2;
|
|---|
| 258 | return tmp;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | Q_COMPAT_EXPORT inline const Q3CString operator+(char c1, const Q3CString &s2)
|
|---|
| 262 | {
|
|---|
| 263 | Q3CString tmp;
|
|---|
| 264 | tmp += c1;
|
|---|
| 265 | tmp += s2;
|
|---|
| 266 | return tmp;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | QT_END_NAMESPACE
|
|---|
| 270 |
|
|---|
| 271 | QT_END_HEADER
|
|---|
| 272 |
|
|---|
| 273 | #endif // Q3CSTRING_H
|
|---|