summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetimeparser.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-02-28 12:03:46 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-03-09 19:27:13 +0000
commit9ed389bf15787266c207435d712b9e225db07ad9 (patch)
treebdebf460ba6a6d6dfa6dc8456415f1ed3e556d99 /src/corelib/tools/qdatetimeparser.cpp
parent326f1fdb7d6550a529217b226cbef78425d32969 (diff)
Bugfix in QDateTimeParser's findTextEntry()
If a later month-or-day were to have a name that's a prefix of an earlier one's name, the code would have selected the longer name as best match when the text matched is the shorter name, simply because it found that one first. (Found, on Turkish Cuma(rtesi)? in Thiago's recent new test, by reversing the loop that iterated the list.) Make an exact match win and a match of a full name beat any prefix match of the same length. Change-Id: I8d954b83ccc25e4f47af2e558036d714685cef5e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qdatetimeparser.cpp')
-rw-r--r--src/corelib/tools/qdatetimeparser.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp
index 5871587f8c..62dd25e072 100644
--- a/src/corelib/tools/qdatetimeparser.cpp
+++ b/src/corelib/tools/qdatetimeparser.cpp
@@ -1248,9 +1248,12 @@ end:
\internal
\brief Returns the index in \a entries with the best prefix match to \a text
- Scans \a entries looking for an entry overlapping \a text as much as possible.
- Records the length of overlap in *used (if \a used is non-NULL) and the first
- entry that overlapped this much in *usedText (if \a usedText is non-NULL).
+ Scans \a entries looking for an entry overlapping \a text as much as possible
+ (an exact match beats any prefix match; a match of the full entry as prefix of
+ text beats any entry but one matching a longer prefix; otherwise, the match of
+ longest prefix wins, earlier entries beating later on a draw). Records the
+ length of overlap in *used (if \a used is non-NULL) and the first entry that
+ overlapped this much in *usedText (if \a usedText is non-NULL).
*/
static int findTextEntry(const QString &text, const QVector<QString> &entries, QString *usedText, int *used)
{
@@ -1267,9 +1270,12 @@ static int findTextEntry(const QString &text, const QVector<QString> &entries, Q
int i = 0;
while (i < limit && text.at(i) == name.at(i).toLower())
++i;
- if (i > bestCount) {
+ // Full match beats an equal prefix match:
+ if (i > bestCount || (i == bestCount && i == name.size())) {
bestCount = i;
bestMatch = n;
+ if (i == name.size() && i == text.size())
+ break; // Exact match, name == text, wins.
}
}
if (usedText && bestMatch != -1)