summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstringalgorithms.h
Commit message (Collapse)AuthorAgeFilesLines
* Mark the previously public qstringalgorithms.h functions privateThiago Macieira2017-10-291-18/+22
| | | | | | | | | | | | | | | | | | | | | Discussed during Qt Contributor Summit 2017. We concluded that we don't want to make these functions public, as they do not follow Qt coding style API. Specifically, qStartsWith(a, b) is not easily understood which argument is the needle and which argument is the haystack (same problem memcpy() has). Compare that to a.startsWith(b) which can clearly be read in English as a subject-verb-object sentence. This commit removes the unit tests that called compare(). Discussed-on: http://lists.qt-project.org/pipermail/development/2017-October/031060.html Change-Id: Icaa86fc7b54d4b368c0efffd14ee6205eb9043fb Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QStringView: De-inline the length calculation so we can use SSE2Thiago Macieira2017-09-131-0/+2
| | | | | | | | | | | | | | | | | | Performance is more important in this case than the theoretical benefit of constexpr. This commit implements the SSE2 search for 16-bit null and it might be possible to implement the equivalent for AArch64 (investigation required). It also adds a fallback to wcslen() for systems where wchar_t is short (non-x86 Windows or 32-bit x86 build with -no-sse2). We can re-add the constexpr loop once the C++ language has a way of overloading constexpr and non-constexpr. GCC has a non-standard way to do that with __builtin_constant_p, which is also implemented in this commit, but note that the inline function is still not constexpr. Change-Id: I6e9274c1e7444ad48c81fffd14dcaacafda5ebdc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QStringView/QLatin1String: add trimmed()Marc Mutz2017-05-161-0/+2
| | | | | | | | | | | | | | | | | | | ... using the same qt_trimmed(), qTrimmed(), Q..::trimmed() split we've been using for all other out-of-line string-view member functions to avoid forcing string-view objects onto the stack for the passing of 'this'. In the test, had to fix nullness not being propagated from a QByteArray to the QLatin1String constructed from it. Probably worth fixing in QLatin1String(QByteArray), too. [ChangeLog][QtCore] Added qTrimmed() free functions. [ChangeLog][QtCore][QLatin1String] Added trimmed() function. Change-Id: I73c18ef87e203f30f7552c10dd5c84223bcfae0e Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Move Q_REQUIRED_RESULT to first in line in qstringalgorithms.hMarc Mutz2017-05-161-8/+8
| | | | | | | | Necessary to support C++17's [[nodiscard]] attribute, which needs to be placed at the beginning of a function declaration. Change-Id: I31494d13c7be558e86378782ab8684ef2956730b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live qStartsWith()/qEndsWith()!Marc Mutz2017-04-281-0/+12
| | | | | | | | | | | | | | | | | Following the established pattern of implementing non-mutating string algorithms as free functions over views with a public qFoo() and a static qt_foo() split, add qStartsWith() and qEndsWith(), calling the existing qt_{starts,ends}_with_impl() templates. [ChangeLog][QtCore][QStringAlgorithms] Added qStartsWith(), qEndsWith(). Change-Id: Ic95c2a9c13883a99f1a96319083fb249f20de5f1 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Martin Smith <martin.smith@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Disentangle string-related headersMarc Mutz2017-04-251-0/+68
It's starting to hinder QStringView development (QString::append(QStringView), e.g.). - qbytearray.h includes qstring.h, but is included by qstring.h -> remove qstring.h include from qbytearray.h - the QStringLiteral definition is used from both qstring.h and qstringview.h -> extract into its own header, move QStringViewLiteral definition there, too - the qCompareStrings(), qConvertTo*() functions are used by QString and QStringView -> also extract into own header, included from qstring.h and qstringview.h - QStringView::toString() depends on QString, which depends on QStringView -> move QStringView::toString() definition to qstring.h, after the definition of QString -> move qstringview.h up to all the other includes in qstring.h This is starting to look like a DAG again, and allows to remove the unholy #ifndef QSTRING_H # include <qstring.h> #endif hack from qstringview.h. [ChangeLog][Potentially Source-Incompatible Changes][QByteArray] qbytearray.h no longer includes qstring.h. In particular, this means that in order to use QStringBuilder with QByteArray, you need to include both qbytearray.h and qstring.h now (or <QByteArray> and <QString>, resp.). Change-Id: I7f8acf9c11bc1731266cd25c6eda9fb36723f364 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>