diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2018-05-13 21:53:07 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-06-22 20:12:41 +0000 |
| commit | cad7100fda1b27ba56c4d9efc6bceba62859dfbc (patch) | |
| tree | 942ff836a94aab364ae8c408dcfa44d8808c8134 /src/corelib/tools/qstring.cpp | |
| parent | c699daeceb4448c4545a67ffdba27bcb3b994114 (diff) | |
QByteArray: add compare() with case sensitivity options
Need to do the same for startsWith() and endsWith(). indexOf() is a lot
harder.
[ChangeLog][QtCore][QByteArray] Added compare(), which takes
Qt::CaseSensitivity as one of the parameters. This function is more
efficient than using toLower() or toUpper() and then comparing.
Change-Id: Ib48364abee9f464c96c6fffd152e69bde4194df7
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
| -rw-r--r-- | src/corelib/tools/qstring.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 712e058c9c5..c2e62a47f75 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1076,14 +1076,12 @@ static int qt_compare_strings(QLatin1String lhs, QStringView rhs, Qt::CaseSensit static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { + if (cs == Qt::CaseInsensitive) + return qstrnicmp(lhs.data(), lhs.size(), rhs.data(), rhs.size()); if (lhs.isEmpty()) return lencmp(0, rhs.size()); const auto l = std::min(lhs.size(), rhs.size()); - int r; - if (cs == Qt::CaseSensitive) - r = qstrncmp(lhs.data(), rhs.data(), l); - else - r = qstrnicmp(lhs.data(), rhs.data(), l); + int r = qstrncmp(lhs.data(), rhs.data(), l); return r ? r : lencmp(lhs.size(), rhs.size()); } |
