Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtcontacts-sqlite] Normalize 'x' and 'X' DTMF chars to 'p'
The modem requires the 'p' character for pause; continue to accept
'x' in the DTMF input, but convert the normalized result.
  • Loading branch information
matthewvogt committed Apr 29, 2014
1 parent 867e165 commit af10e08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/extensions/qtcontacts-extensions_impl.h
Expand Up @@ -119,7 +119,13 @@ QString normalize(const QString &input, int flags, int maxCharacters)
if (firstDtmfIndex == -1) {
firstDtmfIndex = subset.length();
}
subset.append(*it);

// Accept 'x' and 'X', but convert them to 'p' in the normalized form
if ((*it).toLower() == QChar::fromLatin1('x')) {
subset.append(QChar::fromLatin1('p'));
} else {
subset.append(*it);
}
}
} else if (flags & QtContactsSqliteExtensions::ValidatePhoneNumber) {
// Invalid character
Expand Down
30 changes: 15 additions & 15 deletions tests/auto/phonenumber/tst_phonenumber.cpp
Expand Up @@ -283,18 +283,18 @@ void tst_PhoneNumber::normalization_data()

QTest::newRow("DTMF 5")
<< "1234567890x1"
<< "1234567890x1"
<< "1234567890p1" // 'x' is converted to 'p'
<< "1234567890"
<< "1234567890x1"
<< "1234567890x1"
<< "1234567890p1"
<< "1234567890p1"
<< true;

QTest::newRow("DTMF 6")
<< "1234567890X1"
<< "1234567890X1"
<< "1234567890p1" // 'X' is converted to 'p'
<< "1234567890"
<< "1234567890X1"
<< "1234567890X1"
<< "1234567890p1"
<< "1234567890p1"
<< true;

QTest::newRow("DTMF 7")
Expand All @@ -315,18 +315,18 @@ void tst_PhoneNumber::normalization_data()

QTest::newRow("DTMF 9")
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2p3#4*5"
<< "1234567890"
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2p3#4*5"
<< "1234567890w1p2p3#4*5"
<< true;

QTest::newRow("DTMF 10")
<< " 1234567890 w1 p2 (x3) #4*5 "
<< "1234567890 w1 p2 (x3) #4*5"
<< "1234567890 w1 p2 (p3) #4*5"
<< "1234567890"
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2x3#4*5"
<< "1234567890w1p2p3#4*5"
<< "1234567890w1p2p3#4*5"
<< true;

QTest::newRow("invalid DTMF 1")
Expand All @@ -339,10 +339,10 @@ void tst_PhoneNumber::normalization_data()

QTest::newRow("invalid DTMF 2")
<< "w1p2x3"
<< "1p2x3"
<< "1p2p3"
<< "1"
<< "1p2x3"
<< "1p2x3"
<< "1p2p3"
<< "1p2p3"
<< false;

QTest::newRow("invalid DTMF 3")
Expand Down

0 comments on commit af10e08

Please sign in to comment.