summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Rename new slice() method sliced()Marc Mutz2020-06-111-7/+7
| | | | | | | | | | | | | | The recently-added slice() method has the problem that it's a noun as well as a verb in the imperative. Like std::vector::empty, which is both an adjective and a verb in the imperative, this may cause confusion as to what the function does. Using the passive voice form of slice(), sliced(), removes the confusion. While it can be read as an adjective, too, that doesn't change the meaning compared to the verb form. Change-Id: If0aa01acb6cf5dd5eafa8226e3ea7f7a0c9da4f1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove most overloads taking a QStringRef from the QString APILars Knoll2020-06-111-112/+13
| | | | | | | | | | Add QStringView overloads where they were missing. This keeps things almost 100% source compatible. Task-number: QTBUG-84319 Change-Id: Ica8ee773b2ce655e9597097786117959e34b236e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QString: remove remnants of old multiArg()Marc Mutz2020-06-111-15/+0
| | | | | Change-Id: I3bc5bab491ce74daa37f320ea5d4324f9827e870 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QLatin1String: add toString()Marc Mutz2020-06-101-0/+10
| | | | | | | | | For symmetry with other views. [ChangeLog][QtCore][QLatin1String] Added toString(). Change-Id: I4a0677e2dbd009e8da097f4cb0dbb27a6baf5469 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Ensure left/right/mid behave in a compatible wayLars Knoll2020-06-091-27/+26
| | | | | | | | | | | | | | | | | | | | QString and QStringRef did bounds checking for left/right/mid, whereas QStringView was asserting on out of bounds. Relax the behavior for QStringView and do bounds checking on pos/n as well. This removes a source of potentially hidden errors when porting from QStringRef (or QString) to QStringView. Unfortunately, one difference remains, where QByteArray::left/right() behaves differently (and somewhat more sane) than QString and QStringRef. We're keeping the difference here, as it has been around for many years. Mark left/right/mid as obsolete and to be replaced with the new first/last/slice methods. Change-Id: I18c203799ba78c928a4610a6038089f27696c22e Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Implement first/last/from and slice() for string-like classesLars Knoll2020-06-081-1/+49
| | | | | | | | | | | | These methods are scheduled as a replacement for left/right/mid() in Qt 6 with a consistent, narrow contract that does not allow out of bounds indices, and therefore does permit faster implementations. Change-Id: Iabf22e8d4f3fef3c5e69a17f103e6cddebe420b1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Limit QByteArray's 8-bit support to ASCIIEdward Welbourne2020-06-041-1/+41
| | | | | | | | | | | | | | | | | | | | | Previously it handled Latin-1, which made it incompatible with UTF-8, which is now our preferred 8-bit encoding. For Qt6 it is limited to ASCII. Adjusted tests to match. QLatin1String::compare() turned out to be relying on qstrnicmp()'s Latin-1 handling. Removed some spurious Q_UNLIKELY()s and tidied up code a little in the process. [ChangeLog][QtCore][Important Behavior Changes] Encoding-dependent features of QByteArrray are now limited to ASCII, where previously they worked for the whole of Latin-1. This affects case-insensitive comparison, notably including qstricmp() and qstrnicmp(), and case-transforming functions. Fixes: QTBUG-84323 Change-Id: I2925d9908f8654599195a2860847b17083911b41 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Rename snippet files to match the carved up corelib/tools/Edward Welbourne2020-06-041-12/+12
| | | | | | | | | | | This is a folllow-up to commits 548513a4bd050d3df0a85fed6e2d1a00ce06d2ab and a9aa206b7b8ac4e69f8c46233b4080e00e845ff5, renaming the snippets files referenced by the files moved out of corelib/tools/ to match the new locations of the files using them. Change-Id: I59f5d3c217ef835e9244387cc769e7212de9d8f5 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Add QStringView::split() methodsLars Knoll2020-06-011-7/+52
| | | | | | | | | | | | | Since QString::split() is not going away in Qt 6, we should aim to provide API symmetry here, and ease porting existing code from QString(Ref) to use QStringView. This is easier than having to port everything to use tokenize() at the same time. tokenize() will however lead to better performance and thus should be preferred. Change-Id: I1eb43300a90167c6e9389ab56f416f2bf7edf506 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Refactor splitString to use QStringViewLars Knoll2020-06-011-12/+11
| | | | | | | Instead of a QChar * and a length. Change-Id: Ic07e92fe0889e57c19ce7c1bf6902f3a598fad05 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add support for count() to QStringViewLars Knoll2020-05-301-11/+8
| | | | | | | Make the API more symmetric with regards to both QString and QStringRef. Change-Id: Ia67c53ba708f6c33874d1a127de8e2857ad9b5b8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add toInt() and friends to QStringViewLars Knoll2020-05-291-0/+10
| | | | | | | | | Make the API more symmetric with regards to both QString and QStringRef. Having this available helps making QStringView more of a drop-in replacement for QStringRef. QStringRef is planned to get removed in Qt 6. Change-Id: Ife036c0b55970078f42e1335442ff9ee5f4a2f0d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Change QString::toIntegral_helper to use QStringViewLars Knoll2020-05-251-21/+20
| | | | | | | This implicitly makes it use qsizetype for the length. Change-Id: Ib39a5a8dd71e48b45179079f7c7fe5e4edbdb5eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Adjust resize() behavior of QString and QByteArray to match Qt 5Lars Knoll2020-05-211-8/+2
| | | | | | | | | | | | | resize() to a smaller size does not reallocate in Qt 5 if the container is not shared. Match this here. As a drive-by also fix resize calls on raw data strings to ensure they are null terminated after the resize. Change-Id: Ic4d8830e86ed3f247020d7ece3217cebd344ae96 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QString: throughly port internals to char16_tMarc Mutz2020-05-191-79/+72
| | | | | | | | | | This includes allocating QString data as char16_t instead of ushort. This isn't the end of the port, but an important milestone: the traditional foldChar() functions are now all unused. Change-Id: I766bebc2d70b6972e2045d3474c7f5770f4676d9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QChar: make fullConvertCase()'s result type more usableMarc Mutz2020-05-171-11/+7
| | | | | | | | Move it into the function, give it an explicit size and make it iterable and indicate to QStringView that it's a compatible container. Change-Id: I483d9225ac73ad93f2037489f2d32473c377e8b7 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QString: remove more functions overloaded on charMarc Mutz2020-05-151-32/+0
| | | | | | | | | | | | | | These functions mess in bad ways with the overload set (they, fatally, attract char16_t, e.g.). The no-ascii warning now comes from the QChar(char) constructor, so it's not lost. [ChangeLog][QtCore][QString] Also removed op=(char), op+(char, QString), op+(QString, char). Change-Id: I1471c9ddb4c6869aff6e527516e2c78b80b7d7d3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString: fix an aliasing issue in remove(QString)Marc Mutz2020-05-151-1/+9
| | | | | | | | | | | Even in Qt 5, remove() can be passed an alias to *this. In Qt 6, with the advent of substring sharing, this will become even more pronounced. Use the same fix as was already used in QString::insert(). Pick-to: 5.15 Change-Id: I1a0d3d99fd7dff6e727661646d2cbfdc94df2682 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QString: fix quadratic behavior in QString::remove(QString)Marc Mutz2020-05-141-10/+24
| | | | | | | | | | | | | | | Calling linear-complexity remove(int, int) in a loop is O(N²). Fix by implementing a remove_if()-like algorithm which ensures each character is written at most once, which is linear. [ChangeLog][QtCore][QString] Fixed quadratic worst-case complexity of remove(QString). The function now has linear complexity in all cases. Pick-to: 5.15 Change-Id: I12f70fbc83fb5da4a9aae4bd02f525d7657cc940 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Enforce that statically allocated array-like containers have 0 capacityGiuseppe D'Angelo2020-05-141-0/+3
| | | | | | | | | | | | | | | | It has been the case for both QStringLiteral and QByteArrayLiteral since Qt 5.0, and Q_ARRAY_LITERAL since Qt 6.0. Since it's definitely surprising, add a note in the docs, which is "somehow" consistent with the interpretation of capacity as the biggest possible size before we reallocate. Since it's 0, any manipulation of the size will cause a reallocation. (Alternatively: the capacity() is for how many elements memory was requested from the free store. No memory was allocated, so 0...) Task-number: QTBUG-84069 Change-Id: I5c7d21a22d1bd8b8d9b71143e33d537ca0224acd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QRegExp support from QString and StringListLars Knoll2020-05-141-250/+2
| | | | | | | | | | Replacement methods do now exist in QRegExp, or for QRegularExpression when porting to it. Remove all autotests associated with the old methods. Change-Id: I3ff1e0da4b53adb64d5a48a30aecd8b960f5e633 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move methods using QRegExp in QString(List) over to QRegExpLars Knoll2020-05-141-188/+7
| | | | | | | | The prepares for the removal of those methods from QString and QStringList. The new methods in QRegExp are left as a porting help. Change-Id: Ieffa33a79caf53b83029e9b070c4eb5cadca1418 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Remove QTextCodec references from QString docsLars Knoll2020-05-141-22/+21
| | | | | Change-Id: I2882f8aed61d92ed5eff6efd2e65679e6688454f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Document the string converter classesLars Knoll2020-05-141-2/+2
| | | | | | | | | | Document QStringConverter, QStringDecoder and QStringEncoder. In addition, do some touches to the API, renaming one enum value, add a flags argument to one constructor and make some members private. Change-Id: I8f99dc3d98fb8860cf6fa46301e34b7eb400511b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Ensure the conversion methods in qstringconverter always get a valid stateLars Knoll2020-05-141-4/+8
| | | | | | | | | | | | Make sure that the conversion methods always get a valid state. This is already the ecase then using the new QStringConverter API, ensure the old QTextCodec API also passes in a valid state. This helps simplify the logic inside those methods. Change-Id: I1945e98cdefd46bf1427e11984337f1d62abcaa2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Remove QTextCodec dependency from QStringLars Knoll2020-05-141-17/+2
| | | | | Change-Id: I34cc24c263684f7c04ee49205f9181476bc16c34 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move the UTF conversion methods to qstringconverterLars Knoll2020-05-141-1/+1
| | | | | | | | | | | | | | Separate them from the qutfcodec, so that the codec can later on be moved out of Qt Core. Fix the QUtf methods to take qsizetype instead of int for length arguments. This also makes it possible to not build QTextCodec into the bootstrap lib anymore. Change-Id: I0b4f83139d61b19c651520a2f3a5012aa7e85cb8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString: deprecate fromUtf16(ushort*)/fromUcs4(uint*)Marc Mutz2020-05-131-27/+11
| | | | | | | | | | | | | | ... in favor of existing char16_t* and char32_t* versions. Swap the implementations around so the deprecated version is inline. [ChangeLog][QtCore][QString] The fromUtf16(const ushort*) and fromUcs4(const uint*) functions have been deprecated in favor of the char16_t and char32_t versions, resp. Change-Id: I94ff63ae98d190267da0b1c943d3d9c4e825ef10 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString: fix premature pessimisation in arg(char-ish)Marc Mutz2020-05-131-6/+2
| | | | | | | | | Instead of converting the char or QChar to a QString, convert them to a QStringView, saving the memory allocation. Pick-to: 5.15 Change-Id: I023712ec00172f1c8570e762817bfc3a95e01125 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString: remove op+=(char) and op+=(QChar::SpecialCharacter)Marc Mutz2020-05-131-23/+0
| | | | | | | | | | | | | | | | | | | The former messes in bad ways with the overload set (it, fatally, attracts char16_t, e.g.). The latter was probably added in response to ambiguities between (char) and (QChar). While it's harmless now, remove it, since it no longer pulls its weight. The no-ascii warning is now coming from QChar(char), so the protection isn't lost. [ChangeLog][QtCore][QString] The += operators taking char and QChar::SpecialCharacter have been removed as they cause adding a char16_t to QString to call the char overload, losing information. The append() function was not affected. Change-Id: I57116314bcc71c0d9476159513c0c10048239db3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Port qustrlen and qustrchr to char16_tMarc Mutz2020-05-121-14/+14
| | | | | | | Fix callers. Change-Id: Iaf604c890941aa3de3bd31da300b2066e65968ed Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString: optimize insert() of a substringMarc Mutz2020-05-111-5/+2
| | | | | | | | | The old code malloc()ed a buffer to hold a copy of the data if a substring of *this was to be inserted. Instead, use a QVarLengthArray. Pick-to: 5.15 Change-Id: Ia3b4d7509bff2375ec0da5c890ecff2e9f7f335c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Port QtPrivate::findString() from ushort* to char16_t*Marc Mutz2020-05-111-7/+7
| | | | | | | Lots of casts disappear... Change-Id: I21be426c9e4629657990ed4c896e4fce537aa1f0 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Modernize foldCase() internal functionsMarc Mutz2020-05-111-1/+1
| | | | | | | | | Overload uint/ushort versions with new char16_t/char32_t ones, and [[deprecate]] the old ones. There's too much churn for doing the replacement in one patch. Change-Id: Ib1f90a1c46b80aa0fb1ea00ce614af49f49bd712 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Port qt_to_latin1() (and it's variants) from ushort to char16_tMarc Mutz2020-05-111-8/+8
| | | | | Change-Id: Id341257f0ac1d6fd1d3176fb34fad253d2bddfb9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Port qt_from_latin1() from ushort to char16_tMarc Mutz2020-05-101-19/+24
| | | | | Change-Id: I054e2f604be7253d3322751d55d03b5bac09aefc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QChar/QString: centralize case folding in qchar.cppMarc Mutz2020-05-091-19/+15
| | | | | | | | | | | | | | | | | | | | | There are (at least) two implementations of the low-level case-folding algorithm, one of which (for QChar::toLower()) seems to be wrong (it doesn't deal with special cases which expand to more than one code point). The algoithm hidden in QString and entangled with the QString detaching code makes reusing the code much harder. At the same time, the dependency of the algorithm on the unicode tables makes exposing a non-allocating result type in the public API hard. std::u16string would be an alternative if we can assure that all implementations use SSO with at least four characters. So, for the time being, leave this as internal API for use in an upcoming QStringView::toLower() as well as case-insensitive hashing. Change-Id: Iabb2611846f6176776aa20e634f44d8464f3305c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QString: fix UB in replace()Marc Mutz2020-05-091-1/+2
| | | | | | | | | | | | | | | Comparing with <, >, <= or >= such pointers as are not pointing into the same array is UB. A clever compiler could look at the code, determine that the only valid execution is for it to return true, and just always take the copy. While that would be benign, it's not guaranteed that this would be the outcome (it's UB, after all), and, of course, we don't want to take the performance hit if we don't need it. Pick-to: 5.15 Change-Id: I48cda232ff10a3c9fd4babcd7e7103a3aed126e8 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* QString: fix UB in insert()Marc Mutz2020-05-091-1/+2
| | | | | | | | | | | | | | | | | | Comparing with <, >, <= or >= such pointers as are not pointing into the same array is UB. A clever compiler could look at the code, determine that the only valid execution is for it to return true, and just always take the copy. While that would be benign, it's not guaranteed that this would be the outcome (it's UB, after all), and, of course, we don't want to take the performance hit if we don't need it. Fix by using std::less, which guarantees a total ordering for all pointers. Pick-to: 5.15 Change-Id: If07b9363b2ecd573f259e4fa972b629362061ce5 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* QString: mark qustrlen() as unsuitable for ASanThiago Macieira2020-05-071-0/+5
| | | | | | | | | We load an aligned 16-byte on the first load, even if 14 of the 16 bytes are before the string contents themselves. Pick-To: 5.15 Change-Id: Ibdc95e9af7bd456a94ecfffd1603f2b8c87655b1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Port qt_string_count() to QStringViewMarc Mutz2020-05-071-8/+7
| | | | | | | | | | | It was not using QStringView API, but immediately dropped to bare metal operations (reinterpret_cast, ushort), subjecting itself to ushort -> char16_t issues. The new formulation avoids low-level primitives. Change-Id: I8e75c7ea7409b133ff43bf5c829aa1f8f7503f11 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QString: remove weird uses of QChar::unicode()Marc Mutz2020-05-071-2/+2
| | | | | | | | Both *rc and fillChar have type QChar. So don't use QChar::unicode() to assign them to each other, just use QChar::op=... Change-Id: I050035ca16d613f3c57eb5a582978d23c2f04f36 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2020-05-041-32/+0
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/text/qlocale.cpp src/network/access/qnetworkaccessmanager.cpp Regenerated tests/auto/testlib/selftests/float/CMakeLists.txt Change-Id: I5a8ae42511380ca49a38b13c6fa8a3c5df8bed01
| * Doc: Remove manual duplicate alias descriptionsPaul Wicking2020-04-281-32/+0
| | | | | | | | | | | | | | | | | | | | With the introduction of the \typealias command to QDoc, QDoc generates a standardized line for aliased types. This patch removes duplication caused by the change in QDoc. Change-Id: I1a01c378f85b0decb7c0400a3b21146f0898c6ec Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* | QString: replace a few autos with char32_tMarc Mutz2020-05-021-4/+4
| | | | | | | | | | | | | | | | | | (under protest) Amends 4ba25a092065a6422510a9f4afa4fbbabeda686c. Change-Id: I5d5eecd9196fff34ac008bcb0213f476ccbb1155 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | QStringIterator: port from uint to char32_tMarc Mutz2020-04-261-6/+6
| | | | | | | | | | | | Change-Id: I0ca47b87216478b28e29b0fa1a118ef13b6d7c84 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
* | QString: add append, op+=, prepend, insert taking QStringViewMarc Mutz2020-04-241-0/+35
| | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][QString] Now supports appending, prepending and inserting QStringViews. Change-Id: I7538c050c67590f27d91443eda0b94a4b80b62f2 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | QString::from/toLocal8Bit: Assume locale is utf8 if we don't have codecsLars Knoll2020-04-161-2/+2
| | | | | | | | | | | | | | | | If there is no text codec support, assume local8bit is utf8, not latin1. This is in line with what 99% of all modern systems do. Change-Id: I35ebcd43ef3572a25f549a8375857dcabcfec4ca Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Remove QString::from/toAscii()Lars Knoll2020-04-161-51/+0
| | | | | | | | | | | | | | These methods have been deprecated since 5.0 Change-Id: I3ceed57a364ea59a63ccc51452ab3b4da7140ce4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix warnings when building with MSVC2017Mitch Curtis2020-03-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | qstring.cpp(10210): warning C4267: 'argument': conversion from 'size_t' to 'uint', possible loss of data qcontiguouscache.h(141): warning C4003: not enough arguments for function-like macro invocation 'max' Change-Id: I01f1fc1c85341ea61c86dcffb1b01fe4cde50eea Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>