Commit Graph

9 Commits

Author SHA1 Message Date
Marc Mutz
a5febadac5 QString(Ref): make toLatin1()/toLocal8Bit() null handling consistent
Systematic testing in tst_QStringApiSymmetry revealed a bug in
QStringRef::toLatin1(): a null input did not result in a null output,
but an empty one. This is fixed, for consistency with
QString::toLatin1(), and QString(Ref)::toUtf8(), which behaved
correctly already.

The same bug was found in QString(Ref)::toLocal8Bit(), which is
particularly hideous, as it's documented to fall back to toLatin1(),
which preserves null inputs. Fixed, too.

[ChangeLog][QtCore][QString] toLocal8Bit() now preserves nullness of
the input QString (outputs null QByteArray).

[ChangeLog][QtCore][QStringRef] toLocal8Bit() and toLatin1() now
preserve nullness of the input QStringRef (output null QByteArrays).

Change-Id: I7026211922c287e03d07e89edbad2987aa646e51
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-02-15 20:12:36 +00:00
Lars Knoll
60985aa42b Use qtConfig throughout in qtbase
Use the new qtConfig macro in all pro/pri files.

This required adding some feature entries, and adding
{private,public}Feature to every referenced already existing entry.

Change-Id: I164214dad1154df6ad84e86d99ed14994ef97cf4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-08-19 04:28:05 +00:00
Marc Mutz
a7ae92e67d QStringRef: add missing relational operators against QByteArray
QStringRef op QByteArray was ambiguous between

  bool QStringRef::operator op(const char*) const
  bool operator op(const QStringRef&, const QString&)

QByteArray op QStringRef was ambiguous between

  bool operator op(const QString&, const QStringRef&)
  bool operator op(const char*, const QStringRef&)

Fix by providing more overloads.

[ChangeLog][QtCore] Disambiguated the relational operators
comparing QByteArray with QStringRef (and vice versa).

Change-Id: I1cfa9ecfdd8b4102e652593faf35f6098289bc34
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-08 21:42:33 +00:00
Marc Mutz
f0d9eed064 QString: fix QChar <> QLatin1String relational operators for non-US-ASCII
The implementation used the QString::compare_helper(QChar*, int, char*, int)
overload, which, however, interprets the rhs as a UTF-8 sequence, not as
Latin-1.

Fix by using the (QChar*, int, QLatin1String) overload.

Extend the test to cover this case, too.

Change-Id: I59b26d63d0caec036b80ef8818c75d0cebe519d2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-08 21:35:54 +00:00
Marc Mutz
0843ce8524 tst_qstringapisymmetry: cover QByteArray, const char*, too
As in 032efc2cb2, which added the
API-symmetry test, define the missing relational operators
locally in the test harness until they are fixed in the library.

Change-Id: Ic2688e6b6b3e028a9c29f1a5eb01058375ef3fe9
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2016-06-08 15:32:02 +00:00
Marc Mutz
e0ea0f6178 QChar: optimize comparison with QString{,Ref}
Instead of relying on the QString relational operators to
implicitly convert the QChar to a QString, add relational
operator overloads that compare the QChar without first
turning it into a QString, saving one memory allocation
per comparison, and allowing to mark the operation as
nothrow.

Consequently, in tst_QStringBinOps, verify now that all
relational operations are noexcept.

The added overloads make QChar ==/!= int comparisons
ambiguous. De-ambiguate by providing a constrained
template that matches int and nothing but int (otherwise,
the QChar and the int versions would compete for a
QChar::SpecialCharacter argument, and end up creating
new ambiguities). This solution may not be perfect, but
it can be easily extended should more ambiguities crop up.
The existing overload deals with all patterns found in
qtbase.

Change-Id: I4156d918e9b9134c1da684b8b69e0ee526ad24e3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-04-05 19:47:37 +00:00
Marc Mutz
0683c9291f QChar: add missing relational operators against QLatin1String/QStringRef
For QChar <> QStringRef, equality and inequality were already provided
(via QChar -> QString implicit conversions, to be fixed in a separate
patch). Missing were the less/greater than (or equal) operators.

Added.

For QChar <> QLatin1String, all relational operators were missing.

Added, too.

[ChangeLog][QtCore][QChar] Added missing operator{<,>,<=,>=}
comparing against QLatin1String and QStringRef.

[ChangeLog][QtCore][QChar] Added missing operator{==,!=}
comparing against QLatin1String.

Change-Id: I9941fe7e7281ea560b3bd5970cb9651ffadc1495
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-04-05 15:23:30 +00:00
Marc Mutz
8005fa3524 QStringRef: add missing relational operators against QLatin1String/QString
Equality and inequality were already provided. Missing were the
less/greater than (or equal) operators.

Added.

Moved existing functions around and more similar to the new ones,
to make the whole code section a bit more manageable.

[ChangeLog][QtCore][QStringRef] Added missing operator{<,>,<=,>=}
comparing against QLatin1String and QString.

Change-Id: Idb3c4fa9b38421637987226f3cc1b77f5d4a6309
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-16 08:06:54 +00:00
Marc Mutz
032efc2cb2 Add test for API symmetry of QString/Ref, QLatin1String, QChar
At the moment, only checks the relational operators, where
it already found some which do not compile. In order to
simplify the test, the missing operators are supplied by
the test harness until they are fixed in the library.

Change-Id: Ief5daefa68f15de5f8e559c9378ed83b715b69ee
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-15 08:11:35 +00:00