diff options
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 307 |
1 files changed, 159 insertions, 148 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index ed0c493c7a..04626742bd 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -421,7 +421,7 @@ const QString::Null QString::null = { }; Most of the QChar member functions also exist in QCharRef. However, they are not explicitly documented here. - \sa QString::operator[]() QString::at() QChar + \sa QString::operator[](), QString::at(), QChar */ /*! @@ -467,7 +467,7 @@ const QString::Null QString::null = { }; *} to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello": - \snippet doc/src/snippets/qstring/main.cpp 0 + \snippet qstring/main.cpp 0 QString converts the \c{const char *} data into Unicode using the fromAscii() function. fromAscii() treats ordinals above 128 as Latin-1 @@ -480,7 +480,7 @@ const QString::Null QString::null = { }; You can also provide string data as an array of \l{QChar}s: - \snippet doc/src/snippets/qstring/main.cpp 1 + \snippet qstring/main.cpp 1 QString makes a deep copy of the QChar data, so you can modify it later without experiencing side effects. (If for performance @@ -495,12 +495,12 @@ const QString::Null QString::null = { }; character that can be used on the left side of an assignment. For example: - \snippet doc/src/snippets/qstring/main.cpp 2 + \snippet qstring/main.cpp 2 For read-only access, an alternative syntax is to use the at() function: - \snippet doc/src/snippets/qstring/main.cpp 3 + \snippet qstring/main.cpp 3 The at() function can be faster than \l operator[](), because it never causes a \l{deep copy} to occur. Alternatively, use the @@ -519,7 +519,7 @@ const QString::Null QString::null = { }; usage. For example, if you want to compare a QString with a string literal, you can write code like this and it will work as expected: - \snippet doc/src/snippets/qstring/main.cpp 4 + \snippet qstring/main.cpp 4 You can also pass string literals to functions that take QStrings as arguments, invoking the QString(const char *) @@ -534,7 +534,7 @@ const QString::Null QString::null = { }; character data: append(), prepend(), insert(), replace(), and remove(). For example: - \snippet doc/src/snippets/qstring/main.cpp 5 + \snippet qstring/main.cpp 5 If you are building a QString gradually and know in advance approximately how many characters the QString will contain, you @@ -563,7 +563,7 @@ const QString::Null QString::null = { }; they return -1. For example, here's a typical loop that finds all occurrences of a particular substring: - \snippet doc/src/snippets/qstring/main.cpp 6 + \snippet qstring/main.cpp 6 QString provides many functions for converting numbers into strings and strings into numbers. See the arg() functions, the @@ -642,14 +642,14 @@ const QString::Null QString::null = { }; application is to add the following entry to your \l{qmake Project Files}{qmake project file}: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 0 + \snippet code/src_corelib_tools_qstring.cpp 0 You then need to explicitly call fromAscii(), fromLatin1(), fromUtf8(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1String class, for example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 1 + \snippet code/src_corelib_tools_qstring.cpp 1 Similarly, you must call toAscii(), toLatin1(), toUtf8(), or toLocal8Bit() explicitly to convert the QString to an 8-bit @@ -666,7 +666,7 @@ const QString::Null QString::null = { }; \l{implicitly shared}, QStrings may be treated like \c{int}s or other basic types. For example: - \snippet doc/src/snippets/qstring/main.cpp 7 + \snippet qstring/main.cpp 7 The \c result variable, is a normal variable allocated on the stack. When \c return is called, and because we're returning by @@ -685,7 +685,7 @@ const QString::Null QString::null = { }; string with size 0. A null string is always empty, but an empty string isn't necessarily null: - \snippet doc/src/snippets/qstring/main.cpp 8 + \snippet qstring/main.cpp 8 All functions except isNull() treat null strings the same as empty strings. For example, toAscii().constData() returns a pointer to a @@ -732,7 +732,7 @@ const QString::Null QString::null = { }; complex string from multiple substrings. You will often write code like this: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 0 + \snippet qstring/stringbuilder.cpp 0 There is nothing wrong with either of these string constructions, but there are a few hidden inefficiencies. Beginning with Qt 4.6, @@ -770,13 +770,13 @@ const QString::Null QString::null = { }; \c{QStringBuilder} wherever you want to use it, and use the \c{'%'} operator instead of \c{'+'} when concatenating strings: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 5 + \snippet qstring/stringbuilder.cpp 5 A more global approach which is the most convenient but not entirely source compatible, is to this define in your .pro file: - \snippet doc/src/snippets/qstring/stringbuilder.cpp 3 + \snippet qstring/stringbuilder.cpp 3 and the \c{'+'} will automatically be performed as the \c{QStringBuilder} \c{'%'} everywhere. @@ -1175,12 +1175,12 @@ QString::QString(QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 45 + \snippet qstring/main.cpp 45 If you want to append a certain number of identical characters to the string, use \l operator+=() as follows rather than resize(): - \snippet doc/src/snippets/qstring/main.cpp 46 + \snippet qstring/main.cpp 46 If you want to expand the string so that it reaches a certain width and fill the new positions with a particular character, use @@ -1188,7 +1188,7 @@ QString::QString(QChar ch) If \a size is negative, it is equivalent to passing zero. - \snippet doc/src/snippets/qstring/main.cpp 47 + \snippet qstring/main.cpp 47 \sa truncate(), reserve() */ @@ -1253,7 +1253,7 @@ void QString::resize(int size) we're fairly sure that size is large enough to make a call to reserve() worthwhile: - \snippet doc/src/snippets/qstring/main.cpp 44 + \snippet qstring/main.cpp 44 \sa squeeze(), capacity() */ @@ -1394,7 +1394,7 @@ QString &QString::operator=(QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 26 + \snippet qstring/main.cpp 26 If the given \a position is greater than size(), the array is first extended using resize(). @@ -1478,11 +1478,11 @@ QString& QString::insert(int i, QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 9 + \snippet qstring/main.cpp 9 This is the same as using the insert() function: - \snippet doc/src/snippets/qstring/main.cpp 10 + \snippet qstring/main.cpp 10 The append() function is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string @@ -1574,7 +1574,7 @@ QString &QString::append(QChar ch) Example: - \snippet doc/src/snippets/qstring/main.cpp 36 + \snippet qstring/main.cpp 36 \sa append(), insert() */ @@ -1629,7 +1629,7 @@ QString &QString::append(QChar ch) position + \a n is beyond the end of the string, the string is truncated at the specified \a position. - \snippet doc/src/snippets/qstring/main.cpp 37 + \snippet qstring/main.cpp 37 \sa insert(), replace() */ @@ -1680,7 +1680,7 @@ QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) Example: - \snippet doc/src/snippets/qstring/main.cpp 38 + \snippet qstring/main.cpp 38 This is the same as \c replace(ch, "", cs). @@ -1713,7 +1713,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Removes every occurrence of the regular expression \a rx in the string, and returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 39 + \snippet qstring/main.cpp 39 \sa indexOf(), lastIndexOf(), replace() */ @@ -1725,7 +1725,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Removes every occurrence of the regular expression \a re in the string, and returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 96 + \snippet qstring/main.cpp 96 \sa indexOf(), lastIndexOf(), replace() */ @@ -1738,7 +1738,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) Example: - \snippet doc/src/snippets/qstring/main.cpp 40 + \snippet qstring/main.cpp 40 \sa insert(), remove() */ @@ -1789,13 +1789,13 @@ QString &QString::replace(int pos, int len, QChar after) Example: - \snippet doc/src/snippets/qstring/main.cpp 41 + \snippet qstring/main.cpp 41 \note The replacement text is not rescanned after it is inserted. Example: - \snippet doc/src/snippets/qstring/main.cpp 86 + \snippet qstring/main.cpp 86 */ QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs) { @@ -2214,7 +2214,7 @@ bool QString::operator<(const QLatin1String &other) const \overload operator<() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2236,8 +2236,7 @@ bool QString::operator<(const QLatin1String &other) const go through QObject::tr(), for example. */ -/*! \fn bool operator<=(const QString &s1, const QString &s2) - \relates QString +/*! \fn bool QString::operator<=(const QString &s1, const QString &s2) Returns true if string \a s1 is lexically less than or equal to string \a s2; otherwise returns false. @@ -2258,7 +2257,7 @@ bool QString::operator<(const QLatin1String &other) const \overload operator<=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2280,8 +2279,7 @@ bool QString::operator<(const QLatin1String &other) const go through QObject::tr(), for example. */ -/*! \fn bool operator>(const QString &s1, const QString &s2) - \relates QString +/*! \fn bool QString::operator>(const QString &s1, const QString &s2) Returns true if string \a s1 is lexically greater than string \a s2; otherwise returns false. @@ -2318,7 +2316,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator>() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c @@ -2362,7 +2360,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator>=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded in + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII @@ -2406,7 +2404,7 @@ bool QString::operator>(const QLatin1String &other) const \overload operator!=() The \a other byte array is converted to a QString using the - fromAscii() function. If any NUL characters ('\0') are embedded + fromAscii() function. If any NUL characters ('\\0') are embedded in the byte array, they will be included in the transformation. You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII @@ -2438,7 +2436,7 @@ bool QString::operator>(const QLatin1String &other) const Example: - \snippet doc/src/snippets/qstring/main.cpp 24 + \snippet qstring/main.cpp 24 If \a from is -1, the search starts at the last character; if it is -2, at the next to last character and so on. @@ -2461,7 +2459,7 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const Example: - \snippet doc/src/snippets/qstring/main.cpp 24 + \snippet qstring/main.cpp 24 If \a from is -1, the search starts at the last character; if it is -2, at the next to last character and so on. @@ -2636,7 +2634,7 @@ static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *nee Example: - \snippet doc/src/snippets/qstring/main.cpp 29 + \snippet qstring/main.cpp 29 \sa indexOf(), contains(), count() */ @@ -2675,7 +2673,7 @@ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) c Example: - \snippet doc/src/snippets/qstring/main.cpp 29 + \snippet qstring/main.cpp 29 \sa indexOf(), contains(), count() */ @@ -2765,13 +2763,13 @@ struct QStringCapture string with \a after. Returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 42 + \snippet qstring/main.cpp 42 For regular expressions containing \l{capturing parentheses}, occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced with \a{rx}.cap(1), cap(2), ... - \snippet doc/src/snippets/qstring/main.cpp 43 + \snippet qstring/main.cpp 43 \sa indexOf(), lastIndexOf(), remove(), QRegExp::cap() */ @@ -2923,13 +2921,13 @@ QString& QString::replace(const QRegExp &rx, const QString &after) string with \a after. Returns a reference to the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 87 + \snippet qstring/main.cpp 87 For regular expressions containing capturing groups, - occurrences of \bold{\\1}, \bold{\\2}, ..., in \a after are replaced + occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced with the string captured by the corresponding capturing group. - \snippet doc/src/snippets/qstring/main.cpp 88 + \snippet qstring/main.cpp 88 \sa indexOf(), lastIndexOf(), remove(), QRegularExpression, QRegularExpressionMatch */ @@ -3097,7 +3095,7 @@ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const case sensitive; otherwise the search is case insensitive. Example: - \snippet doc/src/snippets/qstring/main.cpp 17 + \snippet qstring/main.cpp 17 \sa indexOf(), count() */ @@ -3151,7 +3149,7 @@ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const Example: - \snippet doc/src/snippets/qstring/main.cpp 25 + \snippet qstring/main.cpp 25 */ int QString::indexOf(const QRegExp& rx, int from) const { @@ -3172,7 +3170,7 @@ int QString::indexOf(const QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 25 + \snippet qstring/main.cpp 25 */ int QString::indexOf(QRegExp& rx, int from) const { @@ -3188,7 +3186,7 @@ int QString::indexOf(QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 30 + \snippet qstring/main.cpp 30 */ int QString::lastIndexOf(const QRegExp& rx, int from) const { @@ -3209,7 +3207,7 @@ int QString::lastIndexOf(const QRegExp& rx, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 30 + \snippet qstring/main.cpp 30 */ int QString::lastIndexOf(QRegExp& rx, int from) const { @@ -3225,7 +3223,7 @@ int QString::lastIndexOf(QRegExp& rx, int from) const This function counts overlapping matches, so in the example below, there are four instances of "ana" or "ama": - \snippet doc/src/snippets/qstring/main.cpp 18 + \snippet qstring/main.cpp 18 */ int QString::count(const QRegExp& rx) const @@ -3256,7 +3254,7 @@ int QString::count(const QRegExp& rx) const Example: - \snippet doc/src/snippets/qstring/main.cpp 93 + \snippet qstring/main.cpp 93 */ int QString::indexOf(const QRegularExpression& re, int from) const { @@ -3282,7 +3280,7 @@ int QString::indexOf(const QRegularExpression& re, int from) const Example: - \snippet doc/src/snippets/qstring/main.cpp 94 + \snippet qstring/main.cpp 94 */ int QString::lastIndexOf(const QRegularExpression &re, int from) const { @@ -3333,7 +3331,7 @@ bool QString::contains(const QRegularExpression &re) const This function counts overlapping matches, so in the example below, there are four instances of "ana" or "ama": - \snippet doc/src/snippets/qstring/main.cpp 95 + \snippet qstring/main.cpp 95 */ int QString::count(const QRegularExpression &re) const { @@ -3408,13 +3406,13 @@ int QString::count(const QRegularExpression &re) const to skip empty fields and how to deal with leading and trailing separators; see \l{SectionFlags}. - \snippet doc/src/snippets/qstring/main.cpp 52 + \snippet qstring/main.cpp 52 If \a start or \a end is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on. - \snippet doc/src/snippets/qstring/main.cpp 53 + \snippet qstring/main.cpp 53 \sa split() */ @@ -3422,8 +3420,8 @@ int QString::count(const QRegularExpression &re) const /*! \overload section() - \snippet doc/src/snippets/qstring/main.cpp 51 - \snippet doc/src/snippets/qstring/main.cpp 54 + \snippet qstring/main.cpp 51 + \snippet qstring/main.cpp 54 \sa split() */ @@ -3532,12 +3530,12 @@ static QString extractSections(const QList<qt_section_chunk> §ions, This string is treated as a sequence of fields separated by the regular expression, \a reg. - \snippet doc/src/snippets/qstring/main.cpp 55 + \snippet qstring/main.cpp 55 \warning Using this QRegExp version is much more expensive than the overloaded string and character versions. - \sa split() simplified() + \sa split(), simplified() */ QString QString::section(const QRegExp ®, int start, int end, SectionFlags flags) const { @@ -3572,12 +3570,12 @@ QString QString::section(const QRegExp ®, int start, int end, SectionFlags fl This string is treated as a sequence of fields separated by the regular expression, \a re. - \snippet doc/src/snippets/qstring/main.cpp 89 + \snippet qstring/main.cpp 89 \warning Using this QRegularExpression version is much more expensive than the overloaded string and character versions. - \sa split() simplified() + \sa split(), simplified() */ QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const { @@ -3618,7 +3616,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti The entire string is returned if \a n is greater than size() or less than zero. - \snippet doc/src/snippets/qstring/main.cpp 31 + \snippet qstring/main.cpp 31 \sa right(), mid(), startsWith() */ @@ -3636,7 +3634,7 @@ QString QString::left(int n) const The entire string is returned if \a n is greater than size() or less than zero. - \snippet doc/src/snippets/qstring/main.cpp 48 + \snippet qstring/main.cpp 48 \sa left(), mid(), endsWith() */ @@ -3659,7 +3657,7 @@ QString QString::right(int n) const Example: - \snippet doc/src/snippets/qstring/main.cpp 34 + \snippet qstring/main.cpp 34 \sa left(), right() */ @@ -3690,7 +3688,7 @@ QString QString::mid(int position, int n) const If \a cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive. - \snippet doc/src/snippets/qstring/main.cpp 65 + \snippet qstring/main.cpp 65 \sa endsWith() */ @@ -3746,7 +3744,7 @@ bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const If \a cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive. - \snippet doc/src/snippets/qstring/main.cpp 20 + \snippet qstring/main.cpp 20 \sa startsWith() */ @@ -4248,7 +4246,7 @@ QString& QString::setUnicode(const QChar *unicode, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 57 + \snippet qstring/main.cpp 57 \sa trimmed() */ @@ -4338,7 +4336,7 @@ QString QString::simplified() const Example: - \snippet doc/src/snippets/qstring/main.cpp 82 + \snippet qstring/main.cpp 82 Unlike simplified(), trimmed() leaves internal whitespace alone. @@ -4386,7 +4384,7 @@ QString QString::trimmed() const Example: - \snippet doc/src/snippets/qstring/main.cpp 85 + \snippet qstring/main.cpp 85 The return value is of type QCharRef, a helper class for QString. When you get an object of type QCharRef, you can use it as if it @@ -4425,7 +4423,7 @@ modifiable reference. Equivalent to \c at(position). Example: - \snippet doc/src/snippets/qstring/main.cpp 83 + \snippet qstring/main.cpp 83 If \a position is negative, it is equivalent to passing zero. @@ -4445,7 +4443,7 @@ void QString::truncate(int pos) If \a n is greater than size(), the result is an empty string. Example: - \snippet doc/src/snippets/qstring/main.cpp 15 + \snippet qstring/main.cpp 15 If you want to remove characters from the \e beginning of the string, use remove() instead. @@ -4465,7 +4463,7 @@ void QString::chop(int n) Example: - \snippet doc/src/snippets/qstring/main.cpp 21 + \snippet qstring/main.cpp 21 \sa resize() */ @@ -4504,7 +4502,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 58 + \snippet qstring/main.cpp 58 \sa isEmpty(), resize() */ @@ -4515,7 +4513,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 28 + \snippet qstring/main.cpp 28 Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is @@ -4532,7 +4530,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 27 + \snippet qstring/main.cpp 27 \sa size() */ @@ -4544,7 +4542,7 @@ QString& QString::fill(QChar ch, int size) Example: - \snippet doc/src/snippets/qstring/main.cpp 84 + \snippet qstring/main.cpp 84 This operation is typically very fast (\l{constant time}), because QString preallocates extra space at the end of the string @@ -4566,7 +4564,7 @@ QString& QString::fill(QChar ch, int size) \overload operator+=() Appends the byte array \a ba to this string. The byte array is converted - to Unicode using the fromAscii() function. If any NUL characters ('\0') + to Unicode using the fromAscii() function. If any NUL characters ('\\0') are embedded in the \a ba byte array, they will be included in the transformation. @@ -4773,7 +4771,7 @@ QString& QString::fill(QChar ch, int size) a human would expect. Consider sorting user-visible strings with localeAwareCompare(). - \snippet doc/src/snippets/qstring/main.cpp 16 + \snippet qstring/main.cpp 16 \sa operator==(), operator<(), operator>() */ @@ -5057,13 +5055,13 @@ const ushort *QString::utf16() const If \a truncate is false and the size() of the string is more than \a width, then the returned string is a copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 32 + \snippet qstring/main.cpp 32 If \a truncate is true and the size() of the string is more than \a width, then any characters in a copy of the string after position \a width are removed, and the copy is returned. - \snippet doc/src/snippets/qstring/main.cpp 33 + \snippet qstring/main.cpp 33 \sa rightJustified() */ @@ -5093,7 +5091,7 @@ QString QString::leftJustified(int width, QChar fill, bool truncate) const Returns a string of size() \a width that contains the \a fill character followed by the string. For example: - \snippet doc/src/snippets/qstring/main.cpp 49 + \snippet qstring/main.cpp 49 If \a truncate is false and the size() of the string is more than \a width, then the returned string is a copy of the string. @@ -5102,7 +5100,7 @@ QString QString::leftJustified(int width, QChar fill, bool truncate) const \a width, then the resulting string is truncated at position \a width. - \snippet doc/src/snippets/qstring/main.cpp 50 + \snippet qstring/main.cpp 50 \sa leftJustified() */ @@ -5131,7 +5129,7 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const /*! Returns a lowercase copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 75 + \snippet qstring/main.cpp 75 The case conversion will always happen in the 'C' locale. For locale dependent case folding use QLocale::toLower() @@ -5233,7 +5231,20 @@ QString QString::toCaseFolded() const prop = qGetProp(*p); } if (prop->caseFoldSpecial) { + const ushort *specialCase = specialCaseMap + prop->caseFoldDiff; + ushort length = *specialCase++; +#if 0 + int pos = pp - s.d->data; + s.resize(s.d->size + length - 1); + pp = s.d->data + pos; + while (length--) + *pp++ = *specialCase++; +#else //### we currently don't support full case foldings + Q_ASSERT(length == 1); + Q_UNUSED(length) + *pp++ = *specialCase; +#endif } else { *pp++ = *p + prop->caseFoldDiff; } @@ -5254,7 +5265,7 @@ QString QString::toCaseFolded() const /*! Returns an uppercase copy of the string. - \snippet doc/src/snippets/qstring/main.cpp 81 + \snippet qstring/main.cpp 81 The case conversion will always happen in the 'C' locale. For locale dependent case folding use QLocale::toUpper() @@ -5337,14 +5348,14 @@ QString QString::toUpper() const \c{long long}). If you need those, use the standard snprintf() function instead: - \snippet doc/src/snippets/qstring/main.cpp 63 + \snippet qstring/main.cpp 63 \warning We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream: - \snippet doc/src/snippets/qstring/main.cpp 64 + \snippet qstring/main.cpp 64 For \l {QObject::tr()}{translations}, especially if the strings contains more than one escape sequence, you should consider using @@ -5552,7 +5563,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) case lm_t: i = va_arg(ap, int); break; default: i = 0; break; } - subst = locale.d()->longLongToString(i, precision, 10, width, flags); + subst = locale.d->longLongToString(i, precision, 10, width, flags); ++c; break; } @@ -5584,7 +5595,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) base = 16; break; default: break; } - subst = locale.d()->unsLongLongToString(u, precision, base, width, flags); + subst = locale.d->unsLongLongToString(u, precision, base, width, flags); ++c; break; } @@ -5613,7 +5624,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) case 'g': form = QLocalePrivate::DFSignificantDigits; break; default: break; } - subst = locale.d()->doubleToString(d, precision, form, width, flags); + subst = locale.d->doubleToString(d, precision, form, width, flags); ++c; break; } @@ -5647,7 +5658,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) quint64 i = reinterpret_cast<unsigned long>(arg); #endif flags |= QLocalePrivate::Alternate; - subst = locale.d()->unsLongLongToString(i, precision, 16, width, flags); + subst = locale.d->unsLongLongToString(i, precision, 16, width, flags); ++c; break; } @@ -5717,7 +5728,7 @@ QString &QString::vsprintf(const char* cformat, va_list ap) Example: - \snippet doc/src/snippets/qstring/main.cpp 74 + \snippet qstring/main.cpp 74 \sa number(), toULongLong(), toInt(), QLocale::toLongLong() */ @@ -5732,7 +5743,7 @@ qint64 QString::toLongLong(bool *ok, int base) const #endif QLocale c_locale(QLocale::C); - return c_locale.d()->stringToLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators); + return c_locale.d->stringToLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators); } /*! @@ -5752,7 +5763,7 @@ qint64 QString::toLongLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 79 + \snippet qstring/main.cpp 79 \sa number(), toLongLong(), QLocale::toULongLong() */ @@ -5767,7 +5778,7 @@ quint64 QString::toULongLong(bool *ok, int base) const #endif QLocale c_locale(QLocale::C); - return c_locale.d()->stringToUnsLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators); + return c_locale.d->stringToUnsLongLong(*this, base, ok, QLocalePrivate::FailOnGroupSeparators); } /*! @@ -5789,7 +5800,7 @@ quint64 QString::toULongLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 73 + \snippet qstring/main.cpp 73 \sa number(), toULong(), toInt(), QLocale::toLong() */ @@ -5824,7 +5835,7 @@ long QString::toLong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 78 + \snippet qstring/main.cpp 78 \sa number(), QLocale::toULong() */ @@ -5858,7 +5869,7 @@ ulong QString::toULong(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 72 + \snippet qstring/main.cpp 72 \sa number(), toUInt(), toDouble(), QLocale::toInt() */ @@ -5891,7 +5902,7 @@ int QString::toInt(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 77 + \snippet qstring/main.cpp 77 \sa number(), toInt(), QLocale::toUInt() */ @@ -5924,7 +5935,7 @@ uint QString::toUInt(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 76 + \snippet qstring/main.cpp 76 \sa number(), toUShort(), toInt(), QLocale::toShort() */ @@ -5957,7 +5968,7 @@ short QString::toShort(bool *ok, int base) const Example: - \snippet doc/src/snippets/qstring/main.cpp 80 + \snippet qstring/main.cpp 80 \sa number(), toShort(), QLocale::toUShort() */ @@ -5982,31 +5993,31 @@ ushort QString::toUShort(bool *ok, int base) const If a conversion error occurs, \c{*}\a{ok} is set to false; otherwise \c{*}\a{ok} is set to true. - \snippet doc/src/snippets/qstring/main.cpp 66 + \snippet qstring/main.cpp 66 Various string formats for floating point numbers can be converted to double values: - \snippet doc/src/snippets/qstring/main.cpp 67 + \snippet qstring/main.cpp 67 The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble() - \snippet doc/src/snippets/qstring/main.cpp 68 + \snippet qstring/main.cpp 68 For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble(). - \snippet doc/src/snippets/qstring/main.cpp 69 + \snippet qstring/main.cpp 69 - \sa number() QLocale::setDefault() QLocale::toDouble() trimmed() + \sa number(), QLocale::setDefault(), QLocale::toDouble(), trimmed() */ double QString::toDouble(bool *ok) const { QLocale c_locale(QLocale::C); - return c_locale.d()->stringToDouble(*this, ok, QLocalePrivate::FailOnGroupSeparators); + return c_locale.d->stringToDouble(*this, ok, QLocalePrivate::FailOnGroupSeparators); } /*! @@ -6020,7 +6031,7 @@ double QString::toDouble(bool *ok) const Example: - \snippet doc/src/snippets/qstring/main.cpp 71 + \snippet qstring/main.cpp 71 \sa number(), toDouble(), toInt(), QLocale::toFloat() */ @@ -6049,7 +6060,7 @@ float QString::toFloat(bool *ok) const The base is 10 by default and must be between 2 and 36. For bases other than 10, \a n is treated as an unsigned integer. - \snippet doc/src/snippets/qstring/main.cpp 56 + \snippet qstring/main.cpp 56 The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use @@ -6083,7 +6094,7 @@ QString &QString::setNum(qlonglong n, int base) } #endif QLocale locale(QLocale::C); - *this = locale.d()->longLongToString(n, -1, base); + *this = locale.d->longLongToString(n, -1, base); return *this; } @@ -6099,7 +6110,7 @@ QString &QString::setNum(qulonglong n, int base) } #endif QLocale locale(QLocale::C); - *this = locale.d()->unsLongLongToString(n, -1, base); + *this = locale.d->unsLongLongToString(n, -1, base); return *this; } @@ -6156,7 +6167,7 @@ QString &QString::setNum(double n, char f, int prec) } QLocale locale(QLocale::C); - *this = locale.d()->doubleToString(n, prec, form, -1, flags); + *this = locale.d->doubleToString(n, prec, form, -1, flags); return *this; } @@ -6188,7 +6199,7 @@ QString &QString::setNum(double n, char f, int prec) To get a localized string representation of a number, use QLocale::toString() with the appropriate locale. - \snippet doc/src/snippets/qstring/main.cpp 35 + \snippet qstring/main.cpp 35 \sa setNum() */ @@ -6286,7 +6297,7 @@ QString QString::number(double n, char f, int prec) Example: - \snippet doc/src/snippets/qstring/main.cpp 62 + \snippet qstring/main.cpp 62 \sa QStringList::join(), section() */ @@ -6337,18 +6348,18 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit Here's an example where we extract the words in a sentence using one or more whitespace characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 59 + \snippet qstring/main.cpp 59 Here's a similar example, but this time we use any sequence of non-word characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 60 + \snippet qstring/main.cpp 60 Here's a third example where we use a zero-length assertion, \b{\\b} (word boundary), to split the string into an alternating sequence of non-word and word tokens: - \snippet doc/src/snippets/qstring/main.cpp 61 + \snippet qstring/main.cpp 61 \sa QStringList::join(), section() */ @@ -6386,18 +6397,18 @@ QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const Here's an example where we extract the words in a sentence using one or more whitespace characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 90 + \snippet qstring/main.cpp 90 Here's a similar example, but this time we use any sequence of non-word characters as the separator: - \snippet doc/src/snippets/qstring/main.cpp 91 + \snippet qstring/main.cpp 91 Here's a third example where we use a zero-length assertion, - \bold{\\b} (word boundary), to split the string into an + \b{\\b} (word boundary), to split the string into an alternating sequence of non-word and word tokens: - \snippet doc/src/snippets/qstring/main.cpp 92 + \snippet qstring/main.cpp 92 \sa QStringList::join(), section() */ @@ -6738,7 +6749,7 @@ static QString replaceArgEscapes(const QString &s, const ArgEscapeData &d, int f This example shows how we might create a \c status string for reporting progress while processing a list of files: - \snippet doc/src/snippets/qstring/main.cpp 11 + \snippet qstring/main.cpp 11 First, \c arg(i) replaces \c %1. Then \c arg(total) replaces \c %2. Finally, \c arg(fileName) replaces \c %3. @@ -6774,7 +6785,7 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const strings \a a1 and \a a2 are replaced in one pass. This can make a difference if \a a1 contains e.g. \c{%1}: - \snippet doc/src/snippets/qstring/main.cpp 13 + \snippet qstring/main.cpp 13 */ /*! @@ -6861,8 +6872,8 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const locale was specified, the "C" locale is used. The 'L' flag is ignored if \a base is not 10. - \snippet doc/src/snippets/qstring/main.cpp 12 - \snippet doc/src/snippets/qstring/main.cpp 14 + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 14 If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the @@ -6898,8 +6909,8 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const using QLocale::setDefault(). The 'L' flag is ignored if \a base is not 10. - \snippet doc/src/snippets/qstring/main.cpp 12 - \snippet doc/src/snippets/qstring/main.cpp 14 + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 14 If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the @@ -6954,14 +6965,14 @@ QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) cons QString arg; if (d.occurrences > d.locale_occurrences) - arg = QLocale::c().d()->longLongToString(a, -1, base, fieldWidth, flags); + arg = QLocale::c().d->longLongToString(a, -1, base, fieldWidth, flags); QString locale_arg; if (d.locale_occurrences > 0) { QLocale locale; if (!locale.numberOptions() & QLocale::OmitGroupSeparator) flags |= QLocalePrivate::ThousandsGroup; - locale_arg = locale.d()->longLongToString(a, -1, base, fieldWidth, flags); + locale_arg = locale.d->longLongToString(a, -1, base, fieldWidth, flags); } return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); @@ -6998,14 +7009,14 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con QString arg; if (d.occurrences > d.locale_occurrences) - arg = QLocale::c().d()->unsLongLongToString(a, -1, base, fieldWidth, flags); + arg = QLocale::c().d->unsLongLongToString(a, -1, base, fieldWidth, flags); QString locale_arg; if (d.locale_occurrences > 0) { QLocale locale; if (!locale.numberOptions() & QLocale::OmitGroupSeparator) flags |= QLocalePrivate::ThousandsGroup; - locale_arg = locale.d()->unsLongLongToString(a, -1, base, fieldWidth, flags); + locale_arg = locale.d->unsLongLongToString(a, -1, base, fieldWidth, flags); } return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); @@ -7082,7 +7093,7 @@ QString QString::arg(char a, int fieldWidth, QChar fillChar) const value produces right-aligned text; a negative value produces left-aligned text. - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 2 + \snippet code/src_corelib_tools_qstring.cpp 2 The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of \a a. The conversion @@ -7132,7 +7143,7 @@ QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillCha QString arg; if (d.occurrences > d.locale_occurrences) - arg = QLocale::c().d()->doubleToString(a, prec, form, fieldWidth, flags); + arg = QLocale::c().d->doubleToString(a, prec, form, fieldWidth, flags); QString locale_arg; if (d.locale_occurrences > 0) { @@ -7140,7 +7151,7 @@ QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillCha if (!locale.numberOptions() & QLocale::OmitGroupSeparator) flags |= QLocalePrivate::ThousandsGroup; - locale_arg = locale.d()->doubleToString(a, prec, form, fieldWidth, flags); + locale_arg = locale.d->doubleToString(a, prec, form, fieldWidth, flags); } return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); @@ -7278,7 +7289,7 @@ bool QString::isRightToLeft() const Example: - \snippet doc/src/snippets/qstring/main.cpp 19 + \snippet qstring/main.cpp 19 Note that the pointer remains valid only as long as the string is not modified by other means. For read-only access, constData() is @@ -7366,8 +7377,8 @@ bool QString::isRightToLeft() const Here's an example of how we can use a QRegExp on raw data in memory without requiring to copy the data into a QString: - \snippet doc/src/snippets/qstring/main.cpp 22 - \snippet doc/src/snippets/qstring/main.cpp 23 + \snippet qstring/main.cpp 22 + \snippet qstring/main.cpp 23 \warning A string created with fromRawData() is \e not '\\0'-terminated, unless the raw data contains a '\\0' character @@ -7438,11 +7449,11 @@ QString &QString::setRawData(const QChar *unicode, int size) the \c{const char *} data. For example, assuming \c str is a QString, - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 3 + \snippet code/src_corelib_tools_qstring.cpp 3 is much faster than - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 4 + \snippet code/src_corelib_tools_qstring.cpp 4 because it doesn't construct four temporary QString objects and make a deep copy of the character data. @@ -7454,7 +7465,7 @@ QString &QString::setRawData(const QChar *unicode, int size) just a very thin wrapper around a \c{const char *}. Using QLatin1String, the example code above becomes - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 5 + \snippet code/src_corelib_tools_qstring.cpp 5 This is a bit longer to type, but it provides exactly the same benefits as the first version of the code, and is faster than @@ -7464,7 +7475,7 @@ QString &QString::setRawData(const QChar *unicode, int size) QLatin1String can be used everywhere a QString is expected. For example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 6 + \snippet code/src_corelib_tools_qstring.cpp 6 \sa QString, QLatin1Char, QStringLiteral */ @@ -8332,7 +8343,7 @@ QString &QString::append(const QStringRef &str) If \a n is greater than size() or less than zero, a reference to the entire string is returned. - \snippet doc/src/snippets/qstring/main.cpp leftRef + \snippet qstring/main.cpp leftRef \sa left(), rightRef(), midRef(), startsWith() */ @@ -8352,7 +8363,7 @@ QStringRef QString::leftRef(int n) const If \a n is greater than size() or less than zero, a reference to the entire string is returned. - \snippet doc/src/snippets/qstring/main.cpp rightRef + \snippet qstring/main.cpp rightRef \sa right(), leftRef(), midRef(), endsWith() */ @@ -8379,7 +8390,7 @@ QStringRef QString::rightRef(int n) const Example: - \snippet doc/src/snippets/qstring/main.cpp midRef + \snippet qstring/main.cpp midRef \sa mid(), leftRef(), rightRef() */ @@ -9123,7 +9134,7 @@ QVector<uint> QStringRef::toUcs4() const Example: - \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 7 + \snippet code/src_corelib_tools_qstring.cpp 7 */ QString QString::toHtmlEscaped() const { |