Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Fix number match length for DTMF-only numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvogt committed Oct 24, 2013
1 parent d8d356d commit a94f343
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/seasidecache.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit a94f343

Please sign in to comment.