From a94f343cae0a99aa19b9edca74d4c11871cca751 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Thu, 24 Oct 2013 16:21:37 +1000 Subject: [PATCH] Fix number match length for DTMF-only numbers --- src/seasidecache.cpp | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index d7dc877..1bf2268 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -339,32 +339,43 @@ int matchLength(const QString &lhs, const QString &rhs) QString::const_iterator ldtmf = firstDtmfChar(lbegin, lend); QString::const_iterator rdtmf = firstDtmfChar(rbegin, rend); - // Start match length calculation at the last non-DTMF digit - QString::const_iterator lit = ldtmf - 1; - QString::const_iterator rit = rdtmf - 1; - + QString::const_iterator lit, rit; + bool processDtmf = false; int matchLength = 0; - while (*lit == *rit) { - ++matchLength; - - --lit; - --rit; - if ((lit == lbegin) || (rit == rbegin)) { - if (*lit == *rit) { - ++matchLength; - - if ((lit == lbegin) && (rit == rbegin)) { - // We have a complete, exact match - this must be the best match - return ExactMatch; + + if ((ldtmf != lbegin) && (rdtmf != rbegin)) { + // Start match length calculation at the last non-DTMF digit + lit = ldtmf - 1; + rit = rdtmf - 1; + + while (*lit == *rit) { + ++matchLength; + + --lit; + --rit; + if ((lit == lbegin) || (rit == rbegin)) { + if (*lit == *rit) { + ++matchLength; + + if ((lit == lbegin) && (rit == rbegin)) { + // We have a complete, exact match - this must be the best match + return ExactMatch; + } else { + // We matched all of one number - continue looking in the DTMF part + processDtmf = true; + } } + break; } - break; } + } else { + // Process the DTMF section for a match + processDtmf = true; } // Have we got a match? if ((matchLength >= QtContactsSqliteExtensions::DefaultMaximumPhoneNumberCharacters) || - ((lit == lbegin) || (rit == rbegin))) { + processDtmf) { // See if the match continues into the DTMF area QString::const_iterator lit = ldtmf; QString::const_iterator rit = rdtmf;