summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qconfig-small.h
blob: 7f2f42a58dbcac450e5ca6fc5f68323494e4c32d (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/

/* Data structures */
#ifndef QT_NO_QUUID_STRING
#  define QT_NO_QUUID_STRING
#endif
#ifndef QT_NO_STL
#  define QT_NO_STL
#endif

/* Dialogs */
#ifndef QT_NO_COLORDIALOG
#  define QT_NO_COLORDIALOG
#endif
#ifndef QT_NO_ERRORMESSAGE
#  define QT_NO_ERRORMESSAGE
#endif
#ifndef QT_NO_FILEDIALOG
#  define QT_NO_FILEDIALOG
#endif
#ifndef QT_NO_FONTDIALOG
#  define QT_NO_FONTDIALOG
#endif
#ifndef QT_NO_INPUTDIALOG
#  define QT_NO_INPUTDIALOG
#endif
#ifndef QT_NO_MESSAGEBOX
#  define QT_NO_MESSAGEBOX
#endif
#ifndef QT_NO_PRINTDIALOG
#  define QT_NO_PRINTDIALOG
#endif
#ifndef QT_NO_PROGRESSDIALOG
#  define QT_NO_PROGRESSDIALOG
#endif
#ifndef QT_NO_TABDIALOG
#  define QT_NO_TABDIALOG
#endif

/* File I/O */
#ifndef QT_NO_TEXTSTREAM
#  define QT_NO_TEXTSTREAM
#endif
#ifndef QT_NO_SETTINGS
#  define QT_NO_SETTINGS
#endif
#ifndef QT_NO_LIBRARY
#  define QT_NO_LIBRARY
#endif

/* Fonts */
#ifndef QT_NO_FREETYPE
#  define QT_NO_FREETYPE
#endif

/* Images */
#ifndef QT_NO_IMAGEFORMATPLUGIN
#  define QT_NO_IMAGEFORMATPLUGIN
#endif
#ifndef QT_NO_IMAGEFORMAT_BMP
#  define QT_NO_IMAGEFORMAT_BMP
#endif
#ifndef QT_NO_IMAGEFORMAT_JPEG
#  define QT_NO_IMAGEFORMAT_JPEG
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
#  define QT_NO_IMAGEFORMAT_PPM
#endif
#ifndef QT_NO_IMAGEFORMAT_XBM
#  define QT_NO_IMAGEFORMAT_XBM
#endif
#ifndef QT_NO_IMAGEFORMAT_XPM
#  define QT_NO_IMAGEFORMAT_XPM
#endif
#ifndef QT_NO_IMAGE_TEXT
#  define QT_NO_IMAGE_TEXT
#endif
#ifndef QT_NO_MOVIE
#  define QT_NO_MOVIE
#endif

/* Internationalization */
#ifndef QT_NO_QWS_INPUTMETHODS
#  define QT_NO_QWS_INPUTMETHODS
#endif
#ifndef QT_NO_TEXTCODEC
#  define QT_NO_TEXTCODEC
#endif
#ifndef QT_NO_CODECS
#  define QT_NO_CODECS
#endif
#ifndef QT_NO_TEXTCODECPLUGIN
#  define QT_NO_TEXTCODECPLUGIN
#endif
#ifndef QT_NO_TRANSLATION
#  define QT_NO_TRANSLATION
#endif
#ifndef QT_NO_TRANSLATION_UTF8
#  define QT_NO_TRANSLATION_UTF8
#endif

/* ItemViews */
#ifndef QT_NO_DIRMODEL
#  define QT_NO_DIRMODEL
#endif
#ifndef QT_NO_PROXYMODEL
#  define QT_NO_PROXYMODEL
#endif
#ifndef QT_NO_SORTFILTERPROXYMODEL
#  define QT_NO_SORTFILTERPROXYMODEL
#endif
#ifndef QT_NO_STRINGLISTMODEL
#  define QT_NO_STRINGLISTMODEL
#endif
#ifndef QT_NO_TABLEVIEW
#  define QT_NO_TABLEVIEW
#endif
#ifndef QT_NO_TREEVIEW
#  define QT_NO_TREEVIEW
#endif

/* Kernel */
#ifndef QT_NO_ACTION
#  define QT_NO_ACTION
#endif
#ifndef QT_NO_CLIPBOARD
#  define QT_NO_CLIPBOARD
#endif
#ifndef QT_NO_DRAGANDDROP
#  define QT_NO_DRAGANDDROP
#endif
#ifndef QT_NO_EFFECTS
#  define QT_NO_EFFECTS
#endif
#ifndef QT_NO_PROPERTIES
#  define QT_NO_PROPERTIES
#endif
#ifndef QT_NO_SESSIONMANAGER
#  define QT_NO_SESSIONMANAGER
#endif
#ifndef QT_NO_SHORTCUT
#  define QT_NO_SHORTCUT
#endif
#ifndef QT_NO_SOUND
#  define QT_NO_SOUND
#endif
#ifndef QT_NO_WHEELEVENT
#  define QT_NO_WHEELEVENT
#endif

/* Networking */
#ifndef QT_NO_COP
#  define QT_NO_COP
#endif
#ifndef QT_NO_HOSTINFO
#  define QT_NO_HOSTINFO
#endif
#ifndef QT_NO_HTTP
#  define QT_NO_HTTP
#endif

/* Painting */
#ifndef QT_NO_COLORNAMES
#  define QT_NO_COLORNAMES
#endif
#ifndef QT_NO_PICTURE
#  define QT_NO_PICTURE
#endif
#ifndef QT_NO_PRINTER
#  define QT_NO_PRINTER
#endif
#ifndef QT_NO_CUPS
#  define QT_NO_CUPS
#endif

/* Qt for Embedded Linux */
#ifndef QT_NO_QWS_SOUNDSERVER
#  define QT_NO_QWS_SOUNDSERVER
#endif
#ifndef QT_NO_QWS_PROPERTIES
#  define QT_NO_QWS_PROPERTIES
#endif

/* Styles */
#ifndef QT_NO_STYLE_MOTIF
#  define QT_NO_STYLE_MOTIF
#endif
#ifndef QT_NO_STYLE_CDE
#  define QT_NO_STYLE_CDE
#endif
#ifndef QT_NO_STYLE_CLEANLOOKS
#  define QT_NO_STYLE_CLEANLOOKS
#endif
#ifndef QT_NO_STYLE_PLASTIQUE
#  define QT_NO_STYLE_PLASTIQUE
#endif
#ifndef QT_NO_STYLE_STYLESHEET
#  define QT_NO_STYLE_STYLESHEET
#endif
#ifndef QT_NO_STYLE_WINDOWSXP
#  define QT_NO_STYLE_WINDOWSXP
#endif

/* Utilities */
#ifndef QT_NO_COMPLETER
#  define QT_NO_COMPLETER
#endif
#ifndef QT_NO_DESKTOPSERVICES
#  define QT_NO_DESKTOPSERVICES
#endif
#ifndef QT_NO_SYSTEMTRAYICON
#  define QT_NO_SYSTEMTRAYICON
#endif

/* Widgets */
#ifndef QT_NO_LCDNUMBER
#  define QT_NO_LCDNUMBER
#endif
#ifndef QT_NO_FONTCOMBOBOX
#  define QT_NO_FONTCOMBOBOX
#endif
#ifndef QT_NO_SPINBOX
#  define QT_NO_SPINBOX
#endif
#ifndef QT_NO_CALENDARWIDGET
#  define QT_NO_CALENDARWIDGET
#endif
#ifndef QT_NO_DATETIMEEDIT
#  define QT_NO_DATETIMEEDIT
#endif
#ifndef QT_NO_MENU
#  define QT_NO_MENU
#endif
#ifndef QT_NO_CONTEXTMENU
#  define QT_NO_CONTEXTMENU
#endif
#ifndef QT_NO_MAINWINDOW
#  define QT_NO_MAINWINDOW
#endif
#ifndef QT_NO_DOCKWIDGET
#  define QT_NO_DOCKWIDGET
#endif
#ifndef QT_NO_TOOLBAR
#  define QT_NO_TOOLBAR
#endif
#ifndef QT_NO_MENUBAR
#  define QT_NO_MENUBAR
#endif
#ifndef QT_NO_WORKSPACE
#  define QT_NO_WORKSPACE
#endif
#ifndef QT_NO_PROGRESSBAR
#  define QT_NO_PROGRESSBAR
#endif
#ifndef QT_NO_SPLITTER
#  define QT_NO_SPLITTER
#endif
#ifndef QT_NO_SIZEGRIP
#  define QT_NO_SIZEGRIP
#endif
#ifndef QT_NO_STACKEDWIDGET
#  define QT_NO_STACKEDWIDGET
#endif
#ifndef QT_NO_TABWIDGET
#  define QT_NO_TABWIDGET
#endif
#ifndef QT_NO_STATUSBAR
#  define QT_NO_STATUSBAR
#endif
#ifndef QT_NO_TABLEWIDGET
#  define QT_NO_TABLEWIDGET
#endif
#ifndef QT_NO_TOOLBUTTON
#  define QT_NO_TOOLBUTTON
#endif
#ifndef QT_NO_TABBAR
#  define QT_NO_TABBAR
#endif
#ifndef QT_NO_TOOLBOX
#  define QT_NO_TOOLBOX
#endif
#ifndef QT_NO_WHATSTHIS
#  define QT_NO_WHATSTHIS
#endif
#ifndef QT_NO_TOOLTIP
#  define QT_NO_TOOLTIP
#endif
#ifndef QT_NO_TREEWIDGET
#  define QT_NO_TREEWIDGET
#endif
#ifndef QT_NO_VALIDATOR
#  define QT_NO_VALIDATOR
#endif
'#n821'>821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt3Support module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/

#include "q3cstring.h"
#include "qregexp.h"
#include "qdatastream.h"

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>

QT_BEGIN_NAMESPACE

/*****************************************************************************
  Q3CString member functions
 *****************************************************************************/

/*!
    \class Q3CString
    \reentrant
    \brief The Q3CString class provides an abstraction of the classic C
    zero-terminated char array (char *).

    \compat

    Q3CString tries to behave like a more convenient \c{const char *}.
    The price of doing this is that some algorithms will perform
    badly. For example, append() is O(length()) since it scans for a
    null terminator. Although you might use Q3CString for text that is
    never exposed to the user, for most purposes, and especially for
    user-visible text, you should use QString. QString provides
    implicit sharing, Unicode and other internationalization support,
    and is well optimized.

    Note that for the Q3CString methods that take a \c{const char *}
    parameter the \c{const char *} must either be 0 (null) or not-null
    and '\0' (NUL byte) terminated; otherwise the results are
    undefined.

    A Q3CString that has not been assigned to anything is \e null, i.e.
    both the length and the data pointer is 0. A Q3CString that
    references the empty string ("", a single '\0' char) is \e empty.
    Both null and empty Q3CStrings are legal parameters to the methods.
    Assigning \c{const char *} 0 to Q3CString produces a null Q3CString.

    The length() function returns the length of the string; resize()
    resizes the string and truncate() truncates the string. A string
    can be filled with a character using fill(). Strings can be left
    or right padded with characters using leftJustify() and
    rightJustify(). Characters, strings and regular expressions can be
    searched for using find() and findRev(), and counted using
    contains().

    Strings and characters can be inserted with insert() and appended
    with append(). A string can be prepended with prepend().
    Characters can be removed from the string with remove() and
    replaced with replace().

    Portions of a string can be extracted using left(), right() and
    mid(). Whitespace can be removed using stripWhiteSpace() and
    simplifyWhiteSpace(). Strings can be converted to uppercase or
    lowercase with upper() and lower() respectively.

    Strings that contain numbers can be converted to numbers with
    toShort(), toInt(), toLong(), toULong(), toFloat() and toDouble().
    Numbers can be converted to strings with setNum().

    Many operators are overloaded to work with Q3CStrings. Q3CString
    also supports some more obscure functions, e.g. sprintf(),
    setStr() and setExpand().

    \sidebar Note on Character Comparisons

    In Q3CString the notion of uppercase and lowercase and of which
    character is greater than or less than another character is locale
    dependent. This affects functions which support a case insensitive
    option or which compare or lowercase or uppercase their arguments.
    Case insensitive operations and comparisons will be accurate if
    both strings contain only ASCII characters. (If \c $LC_CTYPE is
    set, most Unix systems do "the right thing".) Functions that this
    affects include contains(), find(), findRev(), \l operator<(), \l
    operator<=(), \l operator>(), \l operator>=(), lower() and
    upper().

    This issue does not apply to \l{QString}s since they represent
    characters using Unicode.
    \endsidebar

    Performance note: The Q3CString methods for QRegExp searching are
    implemented by converting the Q3CString to a QString and performing
    the search on that. This implies a deep copy of the Q3CString data.
    If you are going to perform many QRegExp searches on a large
    Q3CString, you will get better performance by converting the
    Q3CString to a QString yourself, and then searching in the QString.
*/

/*!
    \fn Q3CString Q3CString::left(uint len)  const

    \internal
*/

/*!
    \fn Q3CString Q3CString::right(uint len) const

    \internal
*/

/*!
    \fn Q3CString Q3CString::mid(uint index, uint len) const

    \internal
*/

/*!
    \fn Q3CString  Q3CString::lower() const

    Use QByteArray::toLower() instead.
*/

/*!
    \fn Q3CString  Q3CString::upper() const

    Use QByteArray::toUpper() instead.
*/

/*!
    \fn Q3CString  Q3CString::stripWhiteSpace() const

    Use QByteArray::trimmed() instead.
*/

/*!
    \fn Q3CString  Q3CString::simplifyWhiteSpace() const

    Use QByteArray::simplified() instead.
*/

/*!
    \fn Q3CString& Q3CString::insert(uint index, const char *c)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::insert(uint index, char c)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::prepend(const char *c)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::remove(uint index, uint len)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(uint index, uint len, const char *c)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(char c, const Q3CString &after)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(char c, const char *after)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(const Q3CString &b, const Q3CString &a)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(const char *b, const char *a)

    \internal
*/

/*!
    \fn Q3CString& Q3CString::replace(char b, char a)

    \internal
*/

/*!
    \fn Q3CString::Q3CString()

    Constructs a null string.

    \sa isNull()
*/

/*!
    \fn Q3CString::Q3CString(const QByteArray &ba)

    Constructs a copy of \a ba.
*/

/*!
    \fn Q3CString::Q3CString(const Q3CString &s)

    Constructs a shallow copy \a s.
*/

/*! \fn Q3CString::Q3CString(int size)
    Constructs a string with room for \a size characters, including
    the '\0'-terminator. Makes a null string if \a size == 0.

    If \a size \> 0, then the first and last characters in the string
    are initialized to '\0'. All other characters are uninitialized.

    \sa resize(), isNull()
*/

/*! \fn Q3CString::Q3CString(const char *str)
    Constructs a string that is a deep copy of \a str.

    If \a str is 0 a null string is created.

    \sa isNull()
*/


/*! \fn Q3CString::Q3CString(const char *str, uint maxsize)

    Constructs a string that is a deep copy of \a str. The copy will
    be at most \a maxsize bytes long including the '\0'-terminator.

    Example:
    \snippet doc/src/snippets/code/src_qt3support_tools_q3cstring.cpp 0

    If \a str contains a 0 byte within the first \a maxsize bytes, the
    resulting Q3CString will be terminated by this 0. If \a str is 0 a
    null string is created.

    \sa isNull()
*/

/*!
    \fn Q3CString &Q3CString::operator=(const QByteArray &ba)

    Assigns byte array \a ba to this Q3CString.
*/

/*!
    \fn Q3CString &Q3CString::operator=(const Q3CString &s)

    Assigns a shallow copy of \a s to this string and returns a
    reference to this string.
*/

/*!
    \fn Q3CString &Q3CString::operator=(const char *str)
    \overload

    Assigns a deep copy of \a str to this string and returns a
    reference to this string.

    If \a str is 0 a null string is created.

    \sa isNull()
*/

/*
    \fn bool Q3CString::isNull() const

    Returns true if the string is null, i.e. if data() == 0; otherwise
    returns false. A null string is also an empty string.

    Example:
    \snippet doc/src/snippets/code/src.qt3support.tools.q3cstring.cpp 1

    \sa isEmpty(), length(), size()
*/

/*
    \fn bool Q3CString::isEmpty() const

    Returns true if the string is empty, i.e. if length() == 0;
    otherwise returns false. An empty string is not always a null
    string.

    See example in isNull().

    \sa isNull(), length(), size()
*/

/*
    \fn uint Q3CString::length() const

    Returns the length of the string, excluding the '\0'-terminator.
    Equivalent to calling \c strlen(data()).

    Null strings and empty strings have zero length.

    \sa size(), isNull(), isEmpty()
*/

/*
    \fn bool Q3CString::truncate(uint pos)

    Truncates the string at position \a pos.

    Equivalent to calling \c resize(pos+1).

    Example:
    \snippet doc/src/snippets/code/src.qt3support.tools.q3cstring.cpp 2

    \sa resize()
*/



/*!
    Implemented as a call to the native vsprintf() (see the manual for
    your C library).

    If the string is shorter than 256 characters, this sprintf() calls
    resize(256) to decrease the chance of memory corruption. The
    string is resized back to its actual length before sprintf()
    returns.

    Example:
    \snippet doc/src/snippets/code/src_qt3support_tools_q3cstring.cpp 3

    \warning All vsprintf() implementations will write past the end of
    the target string (*this) if the \a format specification and
    arguments happen to be longer than the target string, and some
    will also fail if the target string is longer than some arbitrary
    implementation limit.

    Giving user-supplied arguments to sprintf() is risky: Sooner or
    later someone will paste a huge line into your application.
*/

Q3CString &Q3CString::sprintf(const char *format, ...)
{
    detach();
    va_list ap;
    va_start(ap, format);
    if (size() < 256)
        resize(256);                // make string big enough
    qvsnprintf(data(), size(), format, ap);
    resize(qstrlen(constData()));
    va_end(ap);
    return *this;
}



/*!
    \fn Q3CString Q3CString::copy() const

    Returns a deep copy of this string.
*/


/*!
    Returns a string of length \a width (plus one for the terminating
    '\0') that contains this string padded with the \a fill character.

    If the length of the string exceeds \a width and \a truncate is
    false (the default), then the returned string is a copy of the
    string. If the length of the string exceeds \a width and \a
    truncate is true, then the returned string is a left(\a width).

    Example:
    \snippet doc/src/snippets/code/src_qt3support_tools_q3cstring.cpp 4

    \sa rightJustify()
*/

Q3CString Q3CString::leftJustify(uint width, char fill, bool truncate) const
{
    Q3CString result;
    int len = qstrlen(constData());
    int padlen = width - len;
    if (padlen > 0) {
        result.resize(len+padlen);
        memcpy(result.data(), constData(), len);
        memset(result.data()+len, fill, padlen);
    } else {
        if (truncate)
            result = left(width);
        else
            result = *this;
    }
    return result;
}

/*!
    Returns a string of length \a width (plus one for the terminating
    '\0') that contains zero or more of the \a fill character followed
    by this string.

    If the length of the string exceeds \a width and \a truncate is
    false (the default), then the returned string is a copy of the
    string. If the length of the string exceeds \a width and \a
    truncate is true, then the returned string is a left(\a width).

    Example:
    \snippet doc/src/snippets/code/src_qt3support_tools_q3cstring.cpp 5

    \sa leftJustify()
*/

Q3CString Q3CString::rightJustify(uint width, char fill, bool truncate) const
{
    Q3CString result;
    int len = qstrlen(constData());
    int padlen = width - len;
    if (padlen > 0) {
        result.resize(len+padlen);
        memset(result.data(), fill, padlen);
        memcpy(result.data()+padlen, constData(), len);
    } else {
        if (truncate)
            result = left(width);
        else
            result = *this;
    }
    return result;
}

/*!
    Returns the string converted to a \c long value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

long Q3CString::toLong(bool *ok) const
{
    const char *p = constData();
    long val=0;
    const long max_mult = 214748364;
    bool is_ok = false;
    int neg = 0;
    if (!p)
        goto bye;
    while (isspace((uchar) *p))                // skip leading space
        p++;
    if (*p == '-') {
        p++;
        neg = 1;
    } else if (*p == '+') {
        p++;
    }
    if (!isdigit((uchar) *p))
        goto bye;
    while (isdigit((uchar) *p)) {
        if (val > max_mult || (val == max_mult && (*p-'0') > 7+neg))
            goto bye;
        val = 10*val + (*p++ - '0');
    }
    if (neg)
        val = -val;
    while (isspace((uchar) *p))                // skip trailing space
        p++;
    if (*p == '\0')
        is_ok = true;
bye:
    if (ok)
        *ok = is_ok;
    return is_ok ? val : 0;
}

/*!
    Returns the string converted to an \c{unsigned long} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

ulong Q3CString::toULong(bool *ok) const
{
    const char *p = constData();
    ulong val=0;
    const ulong max_mult = 429496729;
    bool is_ok = false;
    if (!p)
        goto bye;
    while (isspace((uchar) *p))                // skip leading space
        p++;
    if (*p == '+')
        p++;
    if (!isdigit((uchar) *p))
        goto bye;
    while (isdigit((uchar) *p)) {
        if (val > max_mult || (val == max_mult && (*p-'0') > 5))
            goto bye;
        val = 10*val + (*p++ - '0');
    }
    while (isspace((uchar) *p))                // skip trailing space
        p++;
    if (*p == '\0')
        is_ok = true;
bye:
    if (ok)
        *ok = is_ok;
    return is_ok ? val : 0;
}

/*!
    Returns the string converted to a \c{short} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, is out of range, or if it has trailing garbage; otherwise
    *\a ok is set to true.
*/

short Q3CString::toShort(bool *ok) const
{
    long v = toLong(ok);
    if (ok && *ok && (v < -32768 || v > 32767))
        *ok = false;
    return (short)v;
}

/*!
    Returns the string converted to an \c{unsigned short} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, is out of range, or if it has trailing garbage; otherwise
    *\a ok is set to true.
*/

ushort Q3CString::toUShort(bool *ok) const
{
    ulong v = toULong(ok);
    if (ok && *ok && (v > 65535))
        *ok = false;
    return (ushort)v;
}


/*!
    Returns the string converted to a \c{int} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

int Q3CString::toInt(bool *ok) const
{
    return (int)toLong(ok);
}

/*!
    Returns the string converted to an \c{unsigned int} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

uint Q3CString::toUInt(bool *ok) const
{
    return (uint)toULong(ok);
}

/*!
    Returns the string converted to a \c{double} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

double Q3CString::toDouble(bool *ok) const
{
    char *end;
    double val = strtod(constData() ? constData() : "", &end);
    if (ok)
        *ok = (constData() && *constData() && (end == 0 || *end == '\0'));
    return val;
}

/*!
    Returns the string converted to a \c{float} value.

    If \a ok is not 0: *\a ok is set to false if the string is not a
    number, or if it has trailing garbage; otherwise *\a ok is set to
    true.
*/

float Q3CString::toFloat(bool *ok) const
{
    return (float)toDouble(ok);
}


/*! \fn Q3CString &Q3CString::setStr(const char *str)
    Makes a deep copy of \a str. Returns a reference to the string.
*/

/*!
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

Q3CString &Q3CString::setNum(long n)
{
    data();
    char buf[20];
    register char *p = &buf[19];
    bool neg;
    if (n < 0) {
        neg = true;
        n = -n;
    } else {
        neg = false;
    }
    *p = '\0';
    do {
        *--p = ((int)(n%10)) + '0';
        n /= 10;
    } while (n);
    if (neg)
        *--p = '-';
    *this = p;
    return *this;
}

/*!
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

Q3CString &Q3CString::setNum(ulong n)
{
    data();
    char buf[20];
    register char *p = &buf[19];
    *p = '\0';
    do {
        *--p = ((int)(n%10)) + '0';
        n /= 10;
    } while (n);
    *this = p;
    return *this;
}

/*!
    \fn Q3CString &Q3CString::setNum(int n)
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

/*!
    \fn Q3CString &Q3CString::setNum(uint n)
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

/*!
    \fn Q3CString &Q3CString::setNum(short n)
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

/*!
    \fn Q3CString &Q3CString::setNum(ushort n)
    \overload

    Sets the string to the string representation of the number \a n
    and returns a reference to the string.
*/

/*!
    Sets the string to the string representation of the number \a n
    and returns a reference to the string.

    The format of the string representation is specified by the format
    character \a f, and the precision (number of digits after the
    decimal point) is specified with \a prec.

    The valid formats for \a f are 'e', 'E', 'f', 'g' and 'G'. The
    formats are the same as for sprintf(); they are explained in \l
    QString::arg().
*/

Q3CString &Q3CString::setNum(double n, char f, int prec)
{
#ifndef QT_NO_DEBUG
    if (!(f=='f' || f=='F' || f=='e' || f=='E' || f=='g' || f=='G'))
        qWarning("Q3CString::setNum: Invalid format char '%c'", f);
#endif
    char format[20];
    register char *fs = format;                        // generate format string
    *fs++ = '%';                                //   "%.<prec>l<f>"
    if (prec > 99)
        prec = 99;
    *fs++ = '.';
    if (prec >= 10) {
        *fs++ = prec / 10 + '0';
        *fs++ = prec % 10 + '0';
    } else {
        *fs++ = prec + '0';
    }
    *fs++ = 'l';
    *fs++ = f;
    *fs = '\0';
    return sprintf(format, n);
}

/*! \fn Q3CString &Q3CString::setNum(float n, char f, int prec)
    \overload
*/

/*!
    Sets the character at position \a index to \a c and expands the
    string if necessary, padding with spaces.

    Returns false if \a index was out of range and the string could
    not be expanded; otherwise returns true.
*/

bool Q3CString::setExpand(uint index, char c)
{
    uint oldlen = length();
    if (index >= oldlen) {
        resize(index+1);
        if (index > oldlen)
            memset(data() + oldlen, ' ', index - oldlen);
    }
    *(data() + index) = c;
    return true;
}


/*
    \fn Q3CString::operator const char *() const

    Returns the string data.
*/


/*!
    \fn Q3CString& Q3CString::append(const char *str)

    Appends string \a str to the string and returns a reference to the
    string. Equivalent to operator+=().
*/



#ifndef QT_NO_DATASTREAM
/*! \fn QDataStream &operator<<(QDataStream &s, const Q3CString &str)
    \relates Q3CString

    Writes string \a str to the stream \a s.

    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
*/
QDataStream &operator<<(QDataStream &d, const Q3CString &s)
{
    if (d.version() >= QDataStream::Qt_4_0)
        return operator<<(d, static_cast<const QByteArray &>(s));

    // we need to add a NUL to keep compatibility with Qt 3's QByteArray
    QByteArray copy = s;
    copy.append('\0');
    return operator<<(d, copy);
}

/*!
  \fn QDataStream &operator>>(QDataStream &s, Q3CString &str)
    \relates Q3CString

    Reads a string into \a str from the stream \a s.

    \sa \link datastreamformat.html Format of the QDataStream operators \endlink
*/
QDataStream &operator>>(QDataStream &d, Q3CString &s) {
    operator>>(d, static_cast<QByteArray &>(s));
    if (d.version() < QDataStream::Qt_4_0 && s.endsWith('\0'))
        s.chop(1);                  // ending NUL
    return d;
}
#endif

/*****************************************************************************
  Documentation for related functions
 *****************************************************************************/

/*!
    \fn bool operator==(const Q3CString &s1, const Q3CString &s2)

    \relates Q3CString

    Returns true if \a s1 and \a s2 are equal; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) == 0.
*/

/*!
    \fn bool operator==(const Q3CString &s1, const char *s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 and \a s2 are equal; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) == 0.
*/

/*!
    \fn bool operator==(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 and \a s2 are equal; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) == 0.
*/

/*!
    \fn bool operator!=(const Q3CString &s1, const Q3CString &s2)

    \relates Q3CString

    Returns true if \a s1 and \a s2 are different; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) != 0.
*/

/*!
    \fn bool operator!=(const Q3CString &s1, const char *s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 and \a s2 are different; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) != 0.
*/

/*!
    \fn bool operator!=(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 and \a s2 are different; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) != 0.
*/

/*!
    \fn bool operator<(const Q3CString &s1, const char *s2)

    \relates Q3CString

    Returns true if \a s1 is less than \a s2; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \< 0.
*/

/*!
    \fn bool operator<(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 is less than \a s2; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \< 0.
*/

/*!
    \fn bool operator<=(const Q3CString &s1, const char *s2)

    \relates Q3CString

    Returns true if \a s1 is less than or equal to \a s2; otherwise
    returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \<= 0.
*/

/*!
    \fn bool operator<=(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 is less than or equal to \a s2; otherwise
    returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \<= 0.
*/

/*!
    \fn bool operator>(const Q3CString &s1, const char *s2)

    \relates Q3CString

    Returns true if \a s1 is greater than \a s2; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \> 0.
*/

/*!
    \fn bool operator>(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 is greater than \a s2; otherwise returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \> 0.
*/

/*!
    \fn bool operator>=(const Q3CString &s1, const char *s2)

    \relates Q3CString

    Returns true if \a s1 is greater than or equal to \a s2; otherwise
    returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \>= 0.
*/

/*!
    \fn bool operator>=(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns true if \a s1 is greater than or equal to \a s2; otherwise
    returns false.

    Equivalent to qstrcmp(\a s1, \a s2) \>= 0.
*/

/*!
    \fn const Q3CString operator+(const Q3CString &s1, const Q3CString &s2)

    \relates Q3CString

    Returns a string which consists of the concatenation of \a s1 and
    \a s2.
*/

/*!
    \fn const Q3CString operator+(const Q3CString &s1, const char *s2)
    \overload

    \relates Q3CString

    Returns a string which consists of the concatenation of \a s1 and \a s2.
*/

/*!
    \fn const Q3CString operator+(const char *s1, const Q3CString &s2)
    \overload

    \relates Q3CString

    Returns a string which consists of the concatenation of \a s1 and \a s2.
*/

/*!
    \fn const Q3CString operator+(const Q3CString &s, char c)
    \overload

    \relates Q3CString

    Returns a string which consists of the concatenation of \a s and \a c.
*/

/*!
    \fn const Q3CString operator+(char c, const Q3CString &s)
    \overload

    \relates Q3CString
    Returns a string which consists of the concatenation of \a c and \a s.
*/

QT_END_NAMESPACE