git.iko.soy/typeable/libphonenumber
on main help sign in
typeable/libphonenumber/include/c_phonenumberutil.h
130 lines 6.0 kB history raw
1#ifndef c_phonenumberutil_h
2#define c_phonenumberutil_h
4#include <stddef.h>
6#include "c_phonenumber.h"
8// Copied from PhoneNumberUtil::PhoneNumberFormat
9// is_same_enum verifies that these values didn't change
10enum phone_number_format {
11 E164,
12 INTERNATIONAL,
13 NATIONAL,
14 RFC3966,
15};
17// Copied from PhoneNumberUtil::PhoneNumberType
18// is_same_enum verifies that these values didn't change
19enum phone_number_type
21 FIXED_LINE,
22 MOBILE,
23 FIXED_LINE_OR_MOBILE,
24 TOLL_FREE,
25 PREMIUM_RATE,
26 SHARED_COST,
27 VOIP,
28 PERSONAL_NUMBER,
29 PAGER,
30 UAN,
31 VOICEMAIL,
32 UNKNOWN,
33};
35// Copied from PhoneNumberUtil::MatchType
36// is_same_enum verifies that these values didn't change
37enum match_type {
38 INVALID_NUMBER,
39 NO_MATCH,
40 SHORT_NSN_MATCH,
41 NSN_MATCH,
42 EXACT_MATCH,
43};
45// Copied from PhoneNumberUtil::ErrorType
46// is_same_enum verifies that these values didn't change
47enum error_type
49 NO_PARSING_ERROR,
50 INVALID_COUNTRY_CODE_ERROR,
51 NOT_A_NUMBER,
52 TOO_SHORT_AFTER_IDD,
53 TOO_SHORT_NSN,
54 TOO_LONG_NSN,
55};
57// Copied from PhoneNumberUtil::ValidationResult
58// is_same_enum verifies that these values didn't change
59enum validation_result
61 IS_POSSIBLE,
62 IS_POSSIBLE_LOCAL_ONLY,
63 INVALID_COUNTRY_CODE,
64 TOO_SHORT,
65 INVALID_LENGTH,
66 TOO_LONG,
67};
69// A string allocated by malloc, might not include the null terminator.
70// It is haskell's responsibility to free it.
71typedef struct
73 char *string;
74 size_t string_size;
75} c_string;
77// In the functions below, if an output parameter is a string, we malloc a
78// buffer and write its pointer and size into the given c_string *.
79//
80// If an input parameter is a string, we "unpack" the c_string into a pair of
81// char const * + size_t, because c2hs cannot natively pass structs by value.
82//
83// If the output is a list of T, we malloc a buffer and write its pointer into
84// the given T **, and its size (in T's) into the given size_t *.
85// If the output is a list of strings, we do the same as if T=c_string.
86//
87// If the output is a PhoneNumber, we either return a PhoneNumber *, or write
88// it into a provided PhoneNumber **. In both cases the PhoneNumber object is
89// allocated by `new` and managed by C++ RAII. In all cases it is haskell's
90// responsibility to call its finalizer (c_phone_number_free);
91void c_phone_number_util_get_supported_regions(c_string **, size_t *);
92void c_phone_number_util_get_supported_global_network_calling_codes(int **, size_t *);
93void c_phone_number_util_get_supported_calling_codes(int **, size_t *);
94void c_phone_number_util_get_supported_types_for_region(char const *, size_t, enum phone_number_type **, size_t *);
95void c_phone_number_util_get_supported_types_for_non_geo_entity(int, enum phone_number_type **, size_t *);
96int c_phone_number_util_is_alpha_number(char const *, size_t);
97void c_phone_number_util_convert_alpha_characters_in_number(char const *, size_t, c_string *);
98void c_phone_number_util_normalize_digits_only(char const *, size_t, c_string *);
99void c_phone_number_util_normalize_dialable_chars_only(char const *, size_t, c_string *);
100void c_phone_number_util_get_national_significant_number(struct CxxPhoneNumber const *, c_string *);
101void c_phone_number_util_get_country_mobile_token(int, c_string *);
102void c_phone_number_util_format(struct CxxPhoneNumber const *, enum phone_number_format, c_string *);
103void c_phone_number_util_format_national_number_with_carrier_code(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
104void c_phone_number_util_format_national_number_with_preferred_carrier_code(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
105void c_phone_number_util_format_number_for_mobile_dialing(struct CxxPhoneNumber const *, char const *, size_t, int, c_string *);
106void c_phone_number_util_format_out_of_country_calling_number(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
107void c_phone_number_util_format_in_original_format(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
108void c_phone_number_util_format_out_of_country_keeping_alpha_chars(struct CxxPhoneNumber const *, char const *, size_t, c_string *);
109// /!\ May return NULL
110struct CxxPhoneNumber *c_phone_number_util_truncate_too_long_number(struct CxxPhoneNumber const *);
111enum phone_number_type c_phone_number_util_get_number_type(struct CxxPhoneNumber const *);
112int c_phone_number_util_is_valid_number(struct CxxPhoneNumber const *);
113int c_phone_number_util_is_valid_number_for_region(struct CxxPhoneNumber const *, char const *, size_t);
114void c_phone_number_util_get_region_code_for_number(struct CxxPhoneNumber const *, c_string *);
115int c_phone_number_util_get_country_code_for_region(char const *, size_t);
116void c_phone_number_util_get_region_code_for_country_code(int, c_string *);
117void c_phone_number_util_get_region_codes_for_country_calling_code(int, c_string **, size_t *);
118int c_phone_number_util_is_nanpa_country(char const *, size_t);
119void c_phone_number_util_get_ndd_prefix_for_region(char const *, size_t, int, c_string *);
120enum validation_result c_phone_number_util_is_possible_number_for_type_with_reason(struct CxxPhoneNumber const *, enum phone_number_type);
121int c_phone_number_util_can_be_internationally_dialed(struct CxxPhoneNumber const *);
122int c_phone_number_util_is_number_geographical_1(struct CxxPhoneNumber const *);
123int c_phone_number_util_is_number_geographical_2(enum phone_number_type, int);
124enum error_type c_phone_number_util_parse(char const *, size_t, char const *, size_t, struct CxxPhoneNumber **);
125enum error_type c_phone_number_util_parse_and_keep_raw_input(char const *, size_t, char const *, size_t, struct CxxPhoneNumber **);
126enum match_type c_phone_number_util_is_number_match(struct CxxPhoneNumber const *, struct CxxPhoneNumber const *);
127enum match_type c_phone_number_util_is_number_match_with_two_strings(char const *, size_t, char const *, size_t);
128enum match_type c_phone_number_util_is_number_match_with_one_string(struct CxxPhoneNumber const *, char const *, size_t);
130#endif