Top |
Functions
Types and Values
#define | E_PHONE_NUMBER_ERROR |
enum | EPhoneNumberFormat |
enum | EPhoneNumberMatch |
enum | EPhoneNumberError |
enum | EPhoneNumberCountrySource |
EPhoneNumber |
Description
This modules provides utility functions for parsing and formatting phone numbers. Under the hood it uses Google's libphonenumber.
Functions
e_phone_number_is_supported ()
gboolean
e_phone_number_is_supported (void
);
Checks if phone number support is available. It is recommended to call this function before using any of the phone-utils functions to ensure that the required functionality is available, and to pick alternative mechanisms if needed.
Since: 3.8
e_phone_number_get_country_code_for_region ()
gint e_phone_number_get_country_code_for_region (const gchar *region_code
,GError **error
);
Retrieves the preferred country calling code for region_code
,
e.g. 358 for "fi" or 1 for "en_USUTF
-8".
If NULL
is passed for region_code
the default region as returned by
e_phone_number_get_default_region()
is used.
Since: 3.8
e_phone_number_get_default_region ()
gchar *
e_phone_number_get_default_region (GError **error
);
Retrieves the current two-letter country code that's used by default for
parsing phone numbers in e_phone_number_from_string()
. It can be useful
to store this number before parsing a bigger number of phone numbers.
The result of this functions depends on the current setup of the
LC_ADDRESS
category: If that category provides a reasonable value
for _NL_ADDRESS_COUNTRY_AB2
this value is returned. Otherwise the
locale name configured for LC_ADDRESS
is parsed.
Returns
a newly allocated string containing the current locale's two-letter code for phone number parsing.
[transfer full]
Since: 3.8
e_phone_number_from_string ()
EPhoneNumber * e_phone_number_from_string (const gchar *phone_number
,const gchar *region_code
,GError **error
);
Parses the string passed in phone_number
. Note that no validation is
performed whether the recognized phone number is valid for a particular
region.
The two-letter country code passed in region_code
only is used if the
phone_number
is not written in international format. The application's
default region as returned by e_phone_number_get_default_region()
is used
if region_code
is NULL
.
If the number is guaranteed to start with a '+' followed by the country
calling code, then "ZZ" can be passed for region_code
.
Returns
a new EPhoneNumber instance on success,
or NULL
on error. Call e_phone_number_free()
to release this instance.
[transfer full]
Since: 3.8
e_phone_number_to_string ()
gchar * e_phone_number_to_string (const EPhoneNumber *phone_number
,EPhoneNumberFormat format
);
Describes the phone_number
according to the rules applying to format
.
Since: 3.8
e_phone_number_get_country_code ()
gint e_phone_number_get_country_code (const EPhoneNumber *phone_number
,EPhoneNumberCountrySource *source
);
Queries the phone_number
's country calling code and optionally stores the country
calling code's origin in source
. For instance when parsing "+1-617-5423789" this
function would return one and assing E_PHONE_NUMBER_COUNTRY_FROM_FQTN to source
.
Parameters
phone_number |
the phone number to query |
|
source |
an optional location for storing the phone number's origin, or |
Since: 3.8
e_phone_number_get_national_number ()
gchar *
e_phone_number_get_national_number (const EPhoneNumber *phone_number
);
Queries the national portion of phone_number
without any call-out
prefixes. For instance when parsing "+1-617-5423789" this function would
return the string "6175423789".
Since: 3.8
e_phone_number_compare ()
EPhoneNumberMatch e_phone_number_compare (const EPhoneNumber *first_number
,const EPhoneNumber *second_number
);
Compares two phone numbers.
Parameters
first_number |
the first EPhoneNumber to compare |
|
second_number |
the second EPhoneNumber to compare |
Since: 3.8
e_phone_number_compare_strings ()
EPhoneNumberMatch e_phone_number_compare_strings (const gchar *first_number
,const gchar *second_number
,GError **error
);
Compares two phone numbers.
Parameters
first_number |
the first EPhoneNumber to compare |
|
second_number |
the second EPhoneNumber to compare |
|
error |
a GError to set an error, if any. |
[out] |
Since: 3.8
e_phone_number_compare_strings_with_region ()
EPhoneNumberMatch e_phone_number_compare_strings_with_region (const gchar *first_number
,const gchar *second_number
,const gchar *region_code
,GError **error
);
Compares two phone numbers within the context of region_code
.
Since: 3.8
e_phone_number_copy ()
EPhoneNumber *
e_phone_number_copy (const EPhoneNumber *phone_number
);
Makes a copy of phone_number
.
Returns
A newly allocated EPhoneNumber instance.
Call e_phone_number_free()
to release this instance.
[transfer full]
Since: 3.8
e_phone_number_free ()
void
e_phone_number_free (EPhoneNumber *phone_number
);
Released the memory occupied by phone_number
.
Since: 3.8
Types and Values
enum EPhoneNumberFormat
The supported formatting rules for phone numbers.
Members
format according E.164: "+493055667788". |
||
a formatted phone number always starting with the country calling code: "+49 30 55667788". |
||
a formatted phone number in national scope, that is without country calling code: "(030) 55667788". |
||
a tel: URL according to RFC 3966: "tel:+49-30-55667788". |
Since: 3.8
enum EPhoneNumberMatch
The strength of a phone number match.
Example 3. Some examples of phone number matches
Let's consider the phone number "+1-221-5423789", then comparing with "+1.221.542.3789" we have get E_PHONE_NUMBER_MATCH_EXACT because country code, region code and local number are matching. Comparing with "2215423789" will result in E_PHONE_NUMBER_MATCH_NATIONAL because the country calling code is missing, but the national portion is matching. Finally comparing with "5423789" gives E_PHONE_NUMBER_MATCH_SHORT. For more detail have a look at the following table:
+1-617-5423789 | +1-221-5423789 | 221-5423789 | 5423789 | |
---|---|---|---|---|
+1-617-5423789 | exact | none | none | short |
+1-221-5423789 | none | exact | national | short |
221-5423789 | none | national | national | short |
5423789 | short | short | short | short |
Members
The phone numbers did not match. |
||
The phone numbers matched exactly. Two phone number strings are an exact match if the country code, national phone number, presence of a leading zero for Italian numbers and any extension present are the same. |
||
The national phone number matched. Two phone number strings match at this strength if either or both has no region specified, and the national phone number and extensions are the same. |
||
The weakest sort of match. Two phone numbers match at this strength if either or both has no region specified, or the region specified is the same, and one national phone number could be a shorter version of the other number. This includes the case where one has an extension specified, and the other does not. |
Since: 3.8
enum EPhoneNumberError
Numeric description of a phone number related error.
Members
the library was built without phone number support |
||
the phone number parser reported a yet unknown error code. |
||
the supplied text is not a phone number. |
||
the supplied phone number has an invalid country calling code. |
||
the remaining text after the country calling code is to short for a phone number. |
||
the text is too short for a phone number. |
||
the text is too long for a phone number. |
Since: 3.8
enum EPhoneNumberCountrySource
The origin of a parsed EPhoneNumber's country calling code.
Members
the EPhoneNumber was build from a fully qualified telephone number that contained a valid country calling code |
||
the parsed phone number started with the current locale's international call prefix, followed by a valid country calling code |
||
the parsed phone didn't start with a (recognizable) country calling code, the code was chosen by checking the current locale settings |
Since: 3.8
EPhoneNumber
typedef struct _EPhoneNumber EPhoneNumber;
This opaque type describes a parsed phone number. It can be copied using
e_phone_number_copy()
. To release it call e_phone_number_free()
.
Since: 3.8