QStringRef: fix trimmed() returning null strings on empty input
The QString API symmetry test strikes again, showing that this is inconsistent with both QString and QByteArray, which both return empty for empty inputs. The fix actually makes the implementation simpler. Extend the QStringRef test to cover null inputs, too. I can't merge the trimmed() test in the API symmetry test until everything is actually consistent. [ChangeLog][QtCore][QStringRef] trimmed() now returns an empty string-ref for an empty input. Before, it would return a null one. Change-Id: I6b35c5f498053c4e15a4a9dd465bc696258e7393 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
This commit is contained in:
parent
0803285fe7
commit
8d32204592
@ -11047,8 +11047,6 @@ QStringRef QStringRef::trimmed() const
|
||||
QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end);
|
||||
if (begin == cbegin() && end == cend())
|
||||
return *this;
|
||||
if (begin == end)
|
||||
return QStringRef();
|
||||
int position = m_position + (begin - cbegin());
|
||||
return QStringRef(m_string, position, end - begin);
|
||||
}
|
||||
|
@ -1862,7 +1862,9 @@ void tst_QStringRef::double_conversion()
|
||||
|
||||
void tst_QStringRef::trimmed()
|
||||
{
|
||||
QString a;
|
||||
QVERIFY(QStringRef().trimmed().isNull());
|
||||
QString a = "";
|
||||
QVERIFY(!QStringRef(&a).trimmed().isNull());
|
||||
QStringRef b;
|
||||
a = "Text";
|
||||
b = a.leftRef(-1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user