Merge lp:~boiko/telephony-service/rtm-fix_1376803 into lp:telephony-service/rtm-14.09

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Bill Filler
Approved revision: 925
Merged at revision: 937
Proposed branch: lp:~boiko/telephony-service/rtm-fix_1376803
Merge into: lp:telephony-service/rtm-14.09
Diff against target: 94 lines (+59/-0)
3 files modified
Ubuntu/Telephony/PhoneNumber/phoneutils.cpp (+20/-0)
Ubuntu/Telephony/PhoneNumber/phoneutils.h (+2/-0)
Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml (+37/-0)
To merge this branch: bzr merge lp:~boiko/telephony-service/rtm-fix_1376803
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+247175@code.launchpad.net

Commit message

Add phone number match to phone utils from libphonenumber. This is mostly useful in phone number replacement cases like:

https://bugs.launchpad.net/messaging-app/+bug/1376803

Description of the change

Add phone number match to phone utils from libphonenumber. This is mostly useful in phone number replacement cases like:

https://bugs.launchpad.net/messaging-app/+bug/1376803

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/Telephony/PhoneNumber/phoneutils.cpp'
2--- Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 2014-12-16 01:06:08 +0000
3+++ Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 2015-01-21 17:04:50 +0000
4@@ -22,6 +22,8 @@
5 #include "phoneutils.h"
6
7 #include <QtCore/QDebug>
8+#include <phonenumbers/phonenumbermatch.h>
9+#include <phonenumbers/phonenumbermatcher.h>
10 #include <phonenumbers/phonenumberutil.h>
11
12
13@@ -96,4 +98,22 @@
14 return QObject::event(event);
15 }
16
17+QStringList PhoneUtils::matchInText(const QString& text, const QString &defaultRegion)
18+{
19+ if (text.isEmpty()) {
20+ return QStringList();
21+ }
22+
23+ QString region = defaultRegion.isEmpty() ? this->defaultRegion() : defaultRegion;
24+
25+ QStringList matches;
26+ i18n::phonenumbers::PhoneNumberMatcher matcher(text.toStdString(), region.toStdString());
27+ if (matcher.HasNext()) {
28+ i18n::phonenumbers::PhoneNumberMatch match;
29+ matcher.Next(&match);
30+ matches.append(QString::fromStdString(match.raw_string()));
31+ }
32+
33+ return matches;
34+}
35
36
37=== modified file 'Ubuntu/Telephony/PhoneNumber/phoneutils.h'
38--- Ubuntu/Telephony/PhoneNumber/phoneutils.h 2014-07-14 23:06:34 +0000
39+++ Ubuntu/Telephony/PhoneNumber/phoneutils.h 2015-01-21 17:04:50 +0000
40@@ -43,6 +43,8 @@
41
42 QString defaultRegion() const;
43
44+ Q_INVOKABLE QStringList matchInText(const QString& text, const QString &defaultRegion = QString());
45+
46 Q_INVOKABLE QString format(const QString &phoneNumber, const QString &defaultRegion = QString(), PhoneNumberFormat format = Auto);
47
48 virtual bool event(QEvent *event);
49
50=== modified file 'Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml'
51--- Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 2014-12-16 01:06:08 +0000
52+++ Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 2015-01-21 17:04:50 +0000
53@@ -47,4 +47,41 @@
54 var localeName = Qt.locale().name
55 compare(PhoneNumber.PhoneUtils.defaultRegion, localeName.substr(localeName.length - 2, 2))
56 }
57+
58+ function test_matchPhone_data()
59+ {
60+ var data = [];
61+ data.push({text: "my 1rst phone number 617-688-0034, ..",
62+ expectedMatches: ["617-688-0034"]}) // Local number
63+ data.push({text: "my 1rst phone number 650 253 0000, ..",
64+ expectedMatches: ["650 253 0000"]}) // Local number
65+ data.push({text: "my phnle number 7327572923, please call me",
66+ expectedMatches: ["7327572923"]}) // Country number
67+ data.push({text: "my international number +558187042155, please call me",
68+ expectedMatches: ["+558187042155"]}) // International number
69+ data.push({text: "this is an invalid number 55555555555, yes yes it is",
70+ expectedMatches: []}) // Invalid number
71+ data.push({text: "could you call me between 15h30-16h yes?",
72+ expectedMatches: []}) // Invalid number
73+ data.push({text: "could you call me between at extension *144 yes?",
74+ expectedMatches: []}) // Special number
75+ data.push({text: "my operator number: #123#, yes",
76+ expectedMatches: []}) // Operators command
77+ return data
78+ }
79+
80+ function compareMatches(matches1, matches2)
81+ {
82+ compare(matches1.length, matches2.length)
83+ for (var i = 0; i < matches1.length; ++i) {
84+ compare(matches1[i], matches2[i])
85+ }
86+ }
87+
88+ function test_matchPhone(data)
89+ {
90+ var actualMatches = PhoneNumber.PhoneUtils.matchInText(data.text, "US")
91+ compareMatches(actualMatches, data.expectedMatches)
92+ }
93 }
94+

Subscribers

People subscribed via source and target branches