aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-11 22:15:03 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-11 22:15:03 +0100
commit85901329b0794b136b96bf745f4ab1572806fc89 (patch)
treef23da7e97cae727f39d825f0fef8348cffb238e4 /src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java
parent3db2e44f186c59429901b2c899e139ea60117a55 (diff)
parentcf5da997da8820b4050f5b87ee9440a0ede36d1f (diff)
downloadjitsi-85901329b0794b136b96bf745f4ab1572806fc89.zip
jitsi-85901329b0794b136b96bf745f4ab1572806fc89.tar.gz
jitsi-85901329b0794b136b96bf745f4ab1572806fc89.tar.bz2
Merge commit 'cf5da99'HEADmaster
Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Diffstat (limited to 'src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java')
-rw-r--r--src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java b/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java
index d1942b2..4d4d417 100644
--- a/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/phonenumbers/PhoneNumberI18nServiceImpl.java
@@ -18,6 +18,9 @@
package net.java.sip.communicator.impl.phonenumbers;
import com.google.i18n.phonenumbers.*;
+import com.google.i18n.phonenumbers.PhoneNumberUtil.*;
+import com.google.i18n.phonenumbers.Phonenumber.*;
+
import net.java.sip.communicator.service.protocol.*;
import org.jitsi.service.configuration.*;
@@ -183,6 +186,33 @@ public class PhoneNumberI18nServiceImpl
}
/**
+ * Tries to format the passed phone number into the international format. If
+ * parsing fails or the string is not recognized as a valid phone number,
+ * the input is returned as is.
+ *
+ * @param phoneNumber The phone number to format.
+ * @return the formatted phone number in the international format.
+ */
+ public String formatForDisplay(String phoneNumber)
+ {
+ try
+ {
+ PhoneNumber pn = PhoneNumberUtil.getInstance().parse(phoneNumber,
+ System.getProperty("user.country"));
+ if (PhoneNumberUtil.getInstance().isPossibleNumber(pn))
+ {
+ return PhoneNumberUtil.getInstance().format(pn,
+ PhoneNumberFormat.INTERNATIONAL);
+ }
+ }
+ catch (NumberParseException e)
+ {
+ }
+
+ return phoneNumber;
+ }
+
+ /**
* Indicates if the given string is possibly a phone number.
*
* @param possibleNumber the string to be verified