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
=== modified file 'Ubuntu/Telephony/PhoneNumber/phoneutils.cpp'
--- Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 2014-12-16 01:06:08 +0000
+++ Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 2015-01-21 17:04:50 +0000
@@ -22,6 +22,8 @@
22#include "phoneutils.h"22#include "phoneutils.h"
2323
24#include <QtCore/QDebug>24#include <QtCore/QDebug>
25#include <phonenumbers/phonenumbermatch.h>
26#include <phonenumbers/phonenumbermatcher.h>
25#include <phonenumbers/phonenumberutil.h>27#include <phonenumbers/phonenumberutil.h>
2628
2729
@@ -96,4 +98,22 @@
96 return QObject::event(event);98 return QObject::event(event);
97}99}
98100
101QStringList PhoneUtils::matchInText(const QString& text, const QString &defaultRegion)
102{
103 if (text.isEmpty()) {
104 return QStringList();
105 }
106
107 QString region = defaultRegion.isEmpty() ? this->defaultRegion() : defaultRegion;
108
109 QStringList matches;
110 i18n::phonenumbers::PhoneNumberMatcher matcher(text.toStdString(), region.toStdString());
111 if (matcher.HasNext()) {
112 i18n::phonenumbers::PhoneNumberMatch match;
113 matcher.Next(&match);
114 matches.append(QString::fromStdString(match.raw_string()));
115 }
116
117 return matches;
118}
99119
100120
=== modified file 'Ubuntu/Telephony/PhoneNumber/phoneutils.h'
--- Ubuntu/Telephony/PhoneNumber/phoneutils.h 2014-07-14 23:06:34 +0000
+++ Ubuntu/Telephony/PhoneNumber/phoneutils.h 2015-01-21 17:04:50 +0000
@@ -43,6 +43,8 @@
4343
44 QString defaultRegion() const;44 QString defaultRegion() const;
4545
46 Q_INVOKABLE QStringList matchInText(const QString& text, const QString &defaultRegion = QString());
47
46 Q_INVOKABLE QString format(const QString &phoneNumber, const QString &defaultRegion = QString(), PhoneNumberFormat format = Auto);48 Q_INVOKABLE QString format(const QString &phoneNumber, const QString &defaultRegion = QString(), PhoneNumberFormat format = Auto);
4749
48 virtual bool event(QEvent *event);50 virtual bool event(QEvent *event);
4951
=== modified file 'Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml'
--- Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 2014-12-16 01:06:08 +0000
+++ Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 2015-01-21 17:04:50 +0000
@@ -47,4 +47,41 @@
47 var localeName = Qt.locale().name47 var localeName = Qt.locale().name
48 compare(PhoneNumber.PhoneUtils.defaultRegion, localeName.substr(localeName.length - 2, 2))48 compare(PhoneNumber.PhoneUtils.defaultRegion, localeName.substr(localeName.length - 2, 2))
49 }49 }
50
51 function test_matchPhone_data()
52 {
53 var data = [];
54 data.push({text: "my 1rst phone number 617-688-0034, ..",
55 expectedMatches: ["617-688-0034"]}) // Local number
56 data.push({text: "my 1rst phone number 650 253 0000, ..",
57 expectedMatches: ["650 253 0000"]}) // Local number
58 data.push({text: "my phnle number 7327572923, please call me",
59 expectedMatches: ["7327572923"]}) // Country number
60 data.push({text: "my international number +558187042155, please call me",
61 expectedMatches: ["+558187042155"]}) // International number
62 data.push({text: "this is an invalid number 55555555555, yes yes it is",
63 expectedMatches: []}) // Invalid number
64 data.push({text: "could you call me between 15h30-16h yes?",
65 expectedMatches: []}) // Invalid number
66 data.push({text: "could you call me between at extension *144 yes?",
67 expectedMatches: []}) // Special number
68 data.push({text: "my operator number: #123#, yes",
69 expectedMatches: []}) // Operators command
70 return data
71 }
72
73 function compareMatches(matches1, matches2)
74 {
75 compare(matches1.length, matches2.length)
76 for (var i = 0; i < matches1.length; ++i) {
77 compare(matches1[i], matches2[i])
78 }
79 }
80
81 function test_matchPhone(data)
82 {
83 var actualMatches = PhoneNumber.PhoneUtils.matchInText(data.text, "US")
84 compareMatches(actualMatches, data.expectedMatches)
85 }
50}86}
87

Subscribers

People subscribed via source and target branches