summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
Commit message (Collapse)AuthorAgeFilesLines
...
* Clean up the QByteArray API and implementationLars Knoll2020-09-032-271/+139
| | | | | | | | | | | | | | Add overloads using a QByteArrayView where it makes sense, and call those inline from the other overloads. Remove overloads that are not required anymore (due to implicit conversion of a const char * to a QByteArrayView). Guard all implementations against passing this object to them. Change-Id: I930156f8b05ce72c32cb8201c70513f2e6e19d3e Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QList/QByteArray/QString: Base GrowsBackwards heuristic on old sizeMårten Nordheim2020-09-032-4/+4
| | | | | | | | | | | If you grow from 10 to 100 characters then even if the point of insertion was the end then it will get the GrowsBackwards option on realloc. By basing it on the oldSize the intention of the position to insert at is better clarified. Change-Id: Ia73f4902e8356d94709556de5704cbfa0e1a3a56 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString/QList: disregard space at front during reserve()Andrei Golubev2020-09-021-1/+1
| | | | | | | | | | Aligned QString, QList to the new agreed upon behavior Aligned QList::resize() along the way to be consistent with QString/QBA Task-number: QTBUG-84320 Change-Id: Ie9d7b4b6ebe54bd373af78d92906144b383bbfe2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QByteArray: Disregard space at front during ::reserve(...)Mårten Nordheim2020-09-021-1/+1
| | | | | | | | | | | | Traditionally when calling reserve it's because you expect to append up to X amount of bytes. We should keep that behavior the same. With another patch still in the works current behavior caused an issue with QStringBuilder in QNAM, as mirrored in the testcase attached. Change-Id: I9792a8f158fc9235e3de48ac8b06ac2c10e7f3dc Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Long live Q{Any,Utf8}StringView!Marc Mutz2020-08-319-29/+1957
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We need to add these two classes at the same time, because QAnyStringView makes all QUtf8StringView relational operators moot. We might want to add some later, esp. for UTF-8/UTf-8 comparisons, to avoid the pessimization that we can't early-out on size() mismatch in QAnyStringView equality operators, but that's an optimization, not a correctness issue, and can be fixed in a source-compatible way even after Qt 6 is released. To deal with the char8_t problem in C++20, make QUtf8StringView a class template out of which two UTF-8 views can be instantiated: the Qt 7 version, which depends on C++20 char8_t as value_type, and the Qt 6 version where value_type is a char. Use inline namespaces to map the QUtf8StringView identifier to one or the other, depending on the C++ version used to compile the user code. The inline namespace names must needs be a bit ugly, as their inline'ness depends on __cpp_char8_t. If we simply used q_v1/q_v2 we'd be blocking these names for Qt inline namespaces forever, because it's likely that inline'ness of other users of inline namespaces in Qt depends on things other than __cpp_char8_t. While inline'ness of namespaces is, theoretically speaking, a compile-time-only property, at least Clang warns about mixed use of inline on a given namespace, so we need to bite the bullet here. This is also the reason for the QT_BEGIN_..._NAMESPACE macros: GCC is ok with the first declaration making a namespace inline, while Clang warns upon re-opening an inline namespace as a non-inline one. [ChangeLog][QtCore][QUtf8StringView] New class. [ChangeLog][QtCore][QAnyStringView] New class. Change-Id: Ia7179760fca0e0b67d52f5accb0a62e389b17913 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Inline some methods that only forward to another overloadLars Knoll2020-08-292-24/+16
| | | | | Change-Id: Iba74962d20c00de8996834f0a003f38c2d2cc3e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use checked string iteration in case conversionsEdward Welbourne2020-08-294-7/+11
| | | | | | | | | | | | | | | | | | The Unicode table code can only be safely called on valid code-points. So code that calls it must only pass it valid Unicode data. The string iterator's Unchecked Unchecked methods only provide this guarantee when the string being iterated is guaranteed to be valid UTF-16; while client code should only use QString, QStringView and friends on valid UTF-16 data, we have no way to be sure they have respected that. So take the few extra cycles to actually check validity in the course of iterating strings, when the resulting code-points are to be passed to the Unicode table look-ups. Add tests that case mapping doesn't access Unicode tables out of range (it'll trigger the new assertion). Added some comments to qchar.h that helped me understand surrogates. Change-Id: Iec2c3106bf1a875bdaa1d622f6cf94d7007e281e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Prepend optimize QStringAndrei Golubev2020-08-292-59/+100
| | | | | | | | Added prepend optimization to QString Task-number: QTBUG-84320 Change-Id: Iaa8df790a10c56ecceb06f7143718fb94874ce76 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Support GrowsBackwards in QByteArrayAndrei Golubev2020-08-292-57/+92
| | | | | | | | | | | | | | | Updated main QByteArray operations to support prepend-optimization path There are still many things to consider especially algorithms that use QByteArray::data() or do raw memory operations (e.g. memcpy) regardless of the underlying memory layout, which was somewhat valid before but will likely break now given free space > 0 at the beginning of the byte array memory. Looked at existing cases in the scope of QByteArray, they seem to be OK. Hopefully, CI would find missed violations if any Task-number: QTBUG-84320 Change-Id: I7990cda165b8e77a397e41df4e145468e7a86be0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QUnicodeTools::DefaultOptionsCompatEdward Welbourne2020-08-281-2/+1
| | | | | | | | | | Used in only one place, declared in a private header with a comment saying to remove it. All callers of the one function that had it as default parameter value are passing a value for the parameter. Task-number: QTBUG-85700 Change-Id: Ic72e4df730740a4023b0a43be6bf7acf33a3166b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Convert QStringView::toWCharArray() to return qsizetypeEdward Welbourne2020-08-282-4/+4
| | | | | | | | As requested in a ### Qt6 comment. Task-number: QTBUG-85700 Change-Id: I28a02bf49f4a6455a21a6032179318ce2915b8ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Inline QString's conversions to integral types, except long long onesEdward Welbourne2020-08-282-39/+18
| | | | | | | | As requested by a ### Qt6 comment. Task-number: QTBUG-85700 Change-Id: I7c2813c0d8fbc38bcd2f7229de3a9d8e1b8b1f03 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLatin1String: finish up the qsizetype conversionEdward Welbourne2020-08-281-2/+2
| | | | | | | | | Correct one QString::lastIndexOf() whose return and parameter had been changed, but body and comment hadn't. Task-number: QTBUG-85700 Change-Id: Icbcd049f72346f0e696e6b22fe0893f6de5a2646 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use qsizetype for the size of QByteArray's raw data methodsEdward Welbourne2020-08-281-7/+2
| | | | | | | | | A ### comment said to use int in setRawData(), which took a uint; but the underlying QArrayDataPointer::fromRawData() takes a qsizetype, so propagate that all the way. Change-Id: Iba1f8d020c509b33f5c202c22c6a9bf85b3bab7f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use char32_t for QLocaleData::zeroUcs() and friendsEdward Welbourne2020-08-284-30/+27
| | | | | | | | | | Also catch some stray ushort that should be char16_t by now, use unicode character values for some constants and rename a UCS2 variable to not claim it's UCS4. Change-Id: I374b791947f5c965eaa22ad5b16060b475081c9d Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Don't second-guess strcoll()Edward Welbourne2020-08-281-8/+3
| | | | | | | | | It's defective on Android, but no worse so than the fall-back we were using; and we can't remember why we had that fall-back anyway. Task-number: QTBUG-63518 Change-Id: I28e9b5c7cc64963c9e3941eb1bad85aced280a9b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use qsizetype in QRegularExpressionMarcel Krems2020-08-282-43/+43
| | | | | | | PCRE2 already uses size_t which we can now make full use of. Change-Id: Icb5efd5c6ef27f2e31a9780bf62f5671ddc603cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* macOS: fix standaloneMonthName implementation for system localeVolker Hilsheimer2020-08-271-5/+23
| | | | | | | | | | | | macOS has specific formatters for the standalone month names, so use them. Change-Id: Ic4ad547c7d1c29d71c85f60301acd5a5f0f263d2 Fixes: QTBUG-86191 Pick-to: 5.15 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Evgeniy Dushistov <dushistov@mail.ru> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Pass QByteArrayView by valueLars Knoll2020-08-272-5/+5
| | | | | | Change-Id: I65df03e7781bac63d98b8d3b59568841601d8f25 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Inline the equality operatorLars Knoll2020-08-272-13/+8
| | | | | | | There's no reason to have this out of line. Change-Id: I52aa2ba941f9c81c2194865b156dbc0a2104363b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change QByteArray to handle large arraysLars Knoll2020-08-273-208/+201
| | | | | | | | | | Use qsizetype throughout. Change-Id: I787af7fcfa17e1be87decb64c41c609cc24be117 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add back QByteArray's relational operators taking QStringSona Kurazyan2020-08-263-0/+105
| | | | | | | | | | | | | QString still has the overloads of relational operators taking QByteArray. Add back QByteArray's relational operators taking QString for symmetry. See also the comments of d7ccd8cb4565c8643b158891c9de3187c1586dc9 for more details. [ChangeLog][EDITORIAL] Remove the changelog about QString/QByteArray operators being removed. They're back. Change-Id: I22c95e727285cf8a5ef79b3a4f9d45cb66319252 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: code tidiesGiuseppe D'Angelo2020-08-261-6/+2
| | | | | | | | Given QList-is-QVector, remove an historical piece of code. Change-Id: I7a8876be8ade6dbaa1822d773b092ddb3c4182d4 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: do not assume QStringViews are NUL terminatedGiuseppe D'Angelo2020-08-251-3/+18
| | | | | | | | | | | The convenience API used to look up the index of a named capturing group expects NUL terminated strings. Therefore, we can't just use it together with QStringViews, which may be not. Use the non-convenience API instead. Pick-to: 5.15 Change-Id: I25ca14de49b13ee1764525f8b19f2550c30c1afa Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringList: inherit the constructors from QListGiuseppe D'Angelo2020-08-252-28/+1
| | | | | | | Otherwise it would be missing some, e.g. QStringList(qsizetype). Change-Id: I5214672e62c98514b37b09d283e6035c799eda99 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QByteDataBuffer: add readPointer functionality using QByteArrayViewMårten Nordheim2020-08-241-0/+49
| | | | | | | | While it could be done before it's nice to not have a custom "local" struct or the size in an out-parameter. Change-Id: Ie910f7060b1dadf037312d45e922f8e2deafe3ec Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringTokenizer: use sliced() instead of mid()Marc Mutz2020-08-231-2/+2
| | | | | | | | The code was developed against the narrow-contract version of mid(), but not updated when mid() became wide-contract. Change-Id: I038054fb3f5acc0085c48fbf36af13dd14c917b8 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Port QLatin1String to qsizetype and add narrow-contract substring functionsMarc Mutz2020-08-233-67/+147
| | | | | | | | | | | | | | | | | | | | | | QLatin1String::mid() etc were changed from narrow to wide contract, but the narrow-contract replacements weren't added. This blocks using the narrow-contract functions in QStringTokenizer. As a drive-by, Q_REQUIRED_RESULT -> [[nodiscard]] and Q_DECL_CONSTEXPR -> constexpr. Also centralize most Q_ASSERT()s in a single function, verify(), in an attempt to reduce the amount of string data generated from the asserts in assertive builds. [ChangeLog][QtCore][QLatin1String] Added from(), sliced(), first(n), last(n) functions. [ChangeLog][QtCore][QLatin1String] size_type/size() is now qsizetype (was: int). This makes QLatin1String(ptr, 0) ambiguous now between the (ptr, ptr) and (ptr, qsizetype) constructors. Change-Id: Ie195f66ae1974eb0752c058aa9f3b0853ed92477 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix a number of qdoc warningsFriedemann Kleint2020-08-201-1/+1
| | | | | | | | | | | - Remove obsolete functions and enumeration values - Remove QObject * parameter from QMetaProperty accessors - Fix renamed enumerations in QSsl - Fix list items to be \li - Fix function signatures and variable names Change-Id: I37c7e6bf2c8ff92bc7b82620bae0a27796f866ab Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Move QStringRef and remains to Qt5CompatKarsten Heimrich2020-08-2010-2260/+42
| | | | | | | | | Export some private functions from QUtf8 to resolve undefined symbols in Qt5Compat after moving QStringRef. Task-number: QTBUG-84437 Change-Id: I9046dcb14ed520d8868a511d79da6e721e26f72b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Refactor QXmlStreamStringRefKarsten Heimrich2020-08-191-0/+1
| | | | | | | | | | | | | Use a QStringPrivate inside the implementation. This saves two pointers, and actually makes this a safe replacement for QStringRef inside the implementation of QXmlStreamReader. Unexport the class as all members are inline, and move it into the QtPrivate namespace as class QXmlString. Change-Id: I43fa4684f569514c8c621838dcc346657ac1a915 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Remove binary compat sources for qbytearray and qstringAllan Sandfeld Jensen2020-08-194-137/+2
| | | | | | | No longer needed in Qt6. Change-Id: I29567e175e07cc3658f0619acfd604abf64f6459 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-149-158/+158
| | | | | | | | Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Drop qunicodecharGiuseppe D'Angelo2020-08-141-6/+1
| | | | | | | | | It's unused except in the definition of QStringLiteral, where we can just use char16_t. The static_assert can also go as it's already checked in qglobal.cpp. Change-Id: I06e8a87b4dea1582cd84957efca1b8ad0d2e0266 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Inline two macros in the unicode tablesEdward Welbourne2020-08-121-10/+6
| | | | | | | | They were only used by one function each, in unicodetables.cpp, so don't need to be macros. Change-Id: I3e7f9f661568862d0a0d265bb8f657a8e0782b13 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add x86 vector implementation of UTF-8 comparison to UTF-16Thiago Macieira2020-08-061-17/+121
| | | | | Change-Id: Ied637aece2a7427b8a2dfffd161181f75b738532 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qustrlen: Add #warnings to explain how to deal with GCC 7.x's ASanThiago Macieira2020-08-051-0/+7
| | | | | | | | | | | | | | | The build breaks by disabling ASan in this function because it also removes its ability to emit SSE2 code. That's clearly broken because all x86_64 can use SSE2. So this adds #warnings so people are told how to choose their solution. Clang doesn't currently define __SANITIZE_ADDRESS__ but I added a conditional just in case some future version does. Fixes: QTBUG-84856 Pick-to: 5.15 Change-Id: I552d244076a447ab92d7fffd1617875fdd8dbe62 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Optimize non-vectorized UTF-8 to UTF-16 comparison to US-ASCIIThiago Macieira2020-08-051-13/+21
| | | | | | | | This allows us to skip the surrogate pair decoding too, since it can't match anyway. Change-Id: Ied637aece2a7427b8a2dfffd16118183e5d76794 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement UTF-16 to UTF-8 case-insensitive compare and make publicThiago Macieira2020-08-054-3/+57
| | | | | Change-Id: Ied637aece2a7427b8a2dfffd16116cf3645c6359 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QtPrivate::isLatin1: fix SSE2 non-SSE4.1 codeThiago Macieira2020-08-051-20/+1
| | | | | | | | | | | | | The implementation was broken. The "high" in PUNPCKHBW's "unpack high data" means the high 64-bit of the 128-bit, not the high byte of a 16- bit word. This never worked. It always passed for me because I don't build non-SSE4.2 code (too old, no longer relevant). So just use the working version of simdTestMask. Pick-to: 5.15 5.12 Change-Id: I35a1b4d0a19a43149daefffd16284542f0de3fa3 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Allow use of charXX_t in QUtf8FunctionsThiago Macieira2020-08-051-2/+42
| | | | | | | Even added an internal char8_t type if the compiler doesn't have one. Change-Id: Ied637aece2a7427b8a2dfffd1611813c345d10ec Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Tidy up unicode table generationEdward Welbourne2020-08-051-11/+8
| | | | | | | | | | Eliminate some needless parentheses, tidy up some spacing and indentation and split some long lines. Change first += after declaration to initializer. Change-Id: I05ff2a6337b7ed14e0a2dc9c03fc784c92b63515 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Document the changed semantics when passing arrays to QByteArray methodsSona Kurazyan2020-08-041-0/+8
| | | | | | | | | | | | | | | | | | | After adding QByteArrayView overloads of QByteArray methods that used to take char*, the way of determining the length of passed fixed-sized array data has changed, due to the QByteArraiyView's optimization to deduce the length at compile time for arrays. Document the behavior and add a changelog item. [ChangeLog][QtCore][QByteArray] When passing fixed size C arrays to QByteArray methods, the length of the data on which the method will operate is determined by array size, and not by scanning for the first '\0' terminator, as it was in Qt 5. Task-number: QTBUG-85815 Change-Id: I11cba17d428791e06c9bd4c7a727b7bd6b6aec3c Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Avoid possible ambiguities with QByteArrayView's comparison operatorsSona Kurazyan2020-08-041-8/+13
| | | | | | | | | | | | | | QByteArrayView's comparison operators are declared in the global namespace, which can collide with the ones declared for other types that are implicitly convertible to QByteArrayView (see the example attached to the bugreport). Changing them to be hidden friends will make them visible only when at least one of the operands is a QByteArrayView, so the ambiguity will be avoided. Fixes: QTBUG-85880 Change-Id: Ic3582269d9bda9a2105336ef0f044ea619af37ba Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Move-enable QByteDataBuffer::{append,prepend}Mårten Nordheim2020-08-011-2/+26
| | | | | Change-Id: I2fd342465475e3a694c8459a54957149f8b418a9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix undefined use of memcpy and memcmpAllan Sandfeld Jensen2020-07-313-8/+15
| | | | | | | Don't call them on a nullptr, even with a length of 0. Change-Id: I7fee23303562e5771697a16365cae12e3e87af6f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString::vasprintf: fix 't' modifier for integers on 64-bitThiago Macieira2020-07-311-2/+5
| | | | | | | | | | | | | ‘t’ Specifies that the argument is a ‘ptrdiff_t’. This modifier was introduced in ISO C99. We use qsizetype, which is the same width as ptrdiff_t, so it makes no difference in va_arg(). Change-Id: Iea47e0f8fc8b40378df7fffd16255730109413a5 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Another round of 0->nullptr cleanupAllan Sandfeld Jensen2020-07-311-3/+3
| | | | | Change-Id: Ic8db7dc252f8fea46eb5a4f334726d6c7f4645a6 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Fix warning in QStringView::compare(QChar) on qsizetype->intThiago Macieira2020-07-301-1/+4
| | | | | | | | | | | | | | | | | | size() - 1 is converted to int as the result, but size() is a qsizetype and could be bigger than INT_MAX. So rewrite to not depend on the cast. This was introduced on b2f79cceb11dfd15ac9eea631bc18ad6b036eb91. I could have replaced size() - 1 with int(size() > 1) - 1, but that's even more complex. To simplify, I split the function in two while retaining the C++11 constexpr requirements. Bonus: removes the use of the ambiguously-named "empty()" function that looks like a verb. Fixes: QTBUG-85665 Pick-to: 5.15 Change-Id: Ieffc3453b88c4517a1dbfffd162338fdb084a376 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QLocale: update qt_asciiToDouble to use qsizetypeThiago Macieira2020-07-312-13/+19
| | | | | | | | No need to change the output variable from int to qsizetype. That would complicate the use of libdouble-conversion, which uses ints. Change-Id: Iea47e0f8fc8b40378df7fffd1624bfdba1189d81 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>