Skip to content

Commit 145be39

Browse files
committed
Format source code
1 parent 8a52097 commit 145be39

11 files changed

+181
-180
lines changed

asterisk/app_numformat.c

+30-30
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
/*** DOCUMENTATION
4545
<function name="FORMAT_NUM" language="en_US">
46-
<synopsis>
46+
<synopsis>
4747
Get formatted number in specific format based on a country.
4848
</synopsis>
4949
<syntax argsep=":">
@@ -79,7 +79,7 @@
7979
</description>
8080
</function>
8181
<function name="IS_VALID_NUM" language="en_US">
82-
<synopsis>
82+
<synopsis>
8383
Check validity of a number.
8484
</synopsis>
8585
<syntax argsep=":">
@@ -115,7 +115,7 @@
115115
</description>
116116
</function>
117117
<function name="NUM_INFO" language="en_US">
118-
<synopsis>
118+
<synopsis>
119119
Get information about a number.
120120
</synopsis>
121121
<syntax argsep=":">
@@ -145,7 +145,7 @@
145145
</description>
146146
</function>
147147
<function name="REGION_INFO" language="en_US">
148-
<synopsis>
148+
<synopsis>
149149
Get information about a country/region.
150150
</synopsis>
151151
<syntax argsep=":">
@@ -270,13 +270,13 @@ static char *cli_formatnum_e164(struct ast_cli_entry *e, int cmd, struct ast_cli
270270
ast_cli(a->fd, " - Number: %s\n", number);
271271
ast_cli(a->fd, " - Country: %s\n", country);
272272

273-
ast_cli(a->fd, "Number validation\n");
274-
ast_cli(a->fd, " - Is valid number: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 0)));
275-
ast_cli(a->fd, " - Is valid short number:: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 1)));
276-
ast_cli(a->fd, " - Is valid number or short number:: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 2)));
277-
ast_cli(a->fd, " - Is valid number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 0)));
278-
ast_cli(a->fd, " - Is valid short number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 1)));
279-
ast_cli(a->fd, " - Is valid number or short number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 2)));
273+
ast_cli(a->fd, "Number validation\n");
274+
ast_cli(a->fd, " - Is valid number: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 0)));
275+
ast_cli(a->fd, " - Is valid short number:: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 1)));
276+
ast_cli(a->fd, " - Is valid number or short number:: %s\n", BOOL2STR((*is_valid_number_fn)(number, country, 0, 2)));
277+
ast_cli(a->fd, " - Is valid number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 0)));
278+
ast_cli(a->fd, " - Is valid short number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 1)));
279+
ast_cli(a->fd, " - Is valid number or short number in %s: %s\n", country, BOOL2STR((*is_valid_number_fn)(number, country, 1, 2)));
280280

281281
ast_cli(a->fd, "Number information\n");
282282
ast_cli(a->fd, " - Country calling code: %d\n", (*get_country_code_fn)(number, country));
@@ -381,24 +381,24 @@ static int valid_num_func_read(struct ast_channel *chan, const char *cmd, char *
381381

382382
// Check validity of the option
383383
if (ast_strlen_zero(option)) {
384-
opt_local = 0;
385-
opt_short_code = 0;
386-
} else if (!strcasecmp(option, "l")) {
387-
opt_local = 1;
388-
opt_short_code = 0;
389-
} else if (!strcasecmp(option, "s")) {
390-
opt_local = 0;
391-
opt_short_code = 1;
392-
} else if (!strcasecmp(option, "ls")) {
393-
opt_local = 1;
394-
opt_short_code = 1;
395-
} else if (!strcasecmp(option, "a")) {
396-
opt_local = 0;
397-
opt_short_code = 2;
398-
} else if (!strcasecmp(option, "la")) {
399-
opt_local = 1;
400-
opt_short_code = 2;
401-
} else {
384+
opt_local = 0;
385+
opt_short_code = 0;
386+
} else if (!strcasecmp(option, "l")) {
387+
opt_local = 1;
388+
opt_short_code = 0;
389+
} else if (!strcasecmp(option, "s")) {
390+
opt_local = 0;
391+
opt_short_code = 1;
392+
} else if (!strcasecmp(option, "ls")) {
393+
opt_local = 1;
394+
opt_short_code = 1;
395+
} else if (!strcasecmp(option, "a")) {
396+
opt_local = 0;
397+
opt_short_code = 2;
398+
} else if (!strcasecmp(option, "la")) {
399+
opt_local = 1;
400+
opt_short_code = 2;
401+
} else {
402402
ast_log(LOG_ERROR, "Invalid option.\n");
403403
return 0;
404404
}
@@ -502,7 +502,7 @@ static int unload_module(void)
502502

503503
static int load_module(void)
504504
{
505-
char *error;
505+
char *error;
506506

507507
/* Register all CLI functions for number formatting */
508508
ast_cli_register_multiple(cli_formatnum, ARRAY_LEN(cli_formatnum));

src/formatting.cpp

+33-35
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

2-
#include <iostream>
32
#include <string>
43

54
#include "formatting.h"
6-
#include "phonenumbers/base/logging.h"
75
#include "phonenumbers/phonenumber.pb.h"
86
#include "phonenumbers/phonenumberutil.h"
97

@@ -14,55 +12,55 @@
1412
using i18n::phonenumbers::PhoneNumber;
1513
using i18n::phonenumbers::PhoneNumberUtil;
1614

17-
int num_format(char* number, char* country, enum phone_format type, char* formatted) {
15+
int num_format(char *number, char *country, enum phone_format type, char *formatted) {
1816

1917
strcpy(formatted, number);
2018

2119
PhoneNumber pnumber;
2220

23-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
21+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
2422
phone_util.Parse(number, country, &pnumber);
2523
if (!phone_util.IsValidNumber(pnumber)) {
2624
strcpy(formatted, number);
2725
return -1;
2826
}
2927

3028
std::string formatted_number;
31-
switch (type){
32-
case PLUSE164:
33-
phone_util.Format(pnumber, PhoneNumberUtil::E164, &formatted_number);
34-
break;
35-
case E164:
36-
phone_util.Format(pnumber, PhoneNumberUtil::E164, &formatted_number);
37-
if(formatted_number.at(0) == '+') {
38-
formatted_number = formatted_number.erase(0, 1);
39-
}
40-
break;
41-
case INTERNATIONAL:
42-
phone_util.Format(pnumber, PhoneNumberUtil::INTERNATIONAL, &formatted_number);
43-
break;
44-
case EXTERNAL_CALL:
45-
phone_util.FormatOutOfCountryCallingNumber(pnumber, country, &formatted_number);
46-
REMOVE_SPACES(formatted_number);
29+
switch (type) {
30+
case PLUSE164:
31+
phone_util.Format(pnumber, PhoneNumberUtil::E164, &formatted_number);
32+
break;
33+
case E164:
34+
phone_util.Format(pnumber, PhoneNumberUtil::E164, &formatted_number);
35+
if (formatted_number.at(0) == '+') {
36+
formatted_number = formatted_number.erase(0, 1);
37+
}
38+
break;
39+
case INTERNATIONAL:
40+
phone_util.Format(pnumber, PhoneNumberUtil::INTERNATIONAL, &formatted_number);
41+
break;
42+
case EXTERNAL_CALL:
43+
phone_util.FormatOutOfCountryCallingNumber(pnumber, country, &formatted_number);
44+
REMOVE_SPACES(formatted_number);
4745
REMOVE_DASHES(formatted_number);
48-
break;
49-
case NATIONAL:
50-
phone_util.Format(pnumber, PhoneNumberUtil::NATIONAL, &formatted_number);
51-
break;
52-
case NATIONAL_COMPACT:
53-
phone_util.Format(pnumber, PhoneNumberUtil::NATIONAL, &formatted_number);
54-
REMOVE_SPACES(formatted_number);
46+
break;
47+
case NATIONAL:
48+
phone_util.Format(pnumber, PhoneNumberUtil::NATIONAL, &formatted_number);
49+
break;
50+
case NATIONAL_COMPACT:
51+
phone_util.Format(pnumber, PhoneNumberUtil::NATIONAL, &formatted_number);
52+
REMOVE_SPACES(formatted_number);
5553
REMOVE_DASHES(formatted_number);
5654
REMOVE_CHAR(formatted_number, ')');
5755
REMOVE_CHAR(formatted_number, '(');
58-
break;
59-
case NATIONAL_SHORT:
60-
formatted_number = std::to_string(pnumber.national_number());
61-
break;
62-
default:
63-
formatted_number = number;
64-
break;
65-
}
56+
break;
57+
case NATIONAL_SHORT:
58+
formatted_number = std::to_string(pnumber.national_number());
59+
break;
60+
default:
61+
formatted_number = number;
62+
break;
63+
}
6664

6765
strcpy(formatted, formatted_number.c_str());
6866

src/formatting.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ extern "C" {
1111
* Example: 0473012345 in BE
1212
*/
1313
enum phone_format {
14-
// +32473012345
14+
// +32473012345
1515
PLUSE164,
1616

17-
// 32473012345
17+
// 32473012345
1818
E164,
1919

20-
// +32 473 01 23 45
20+
// +32 473 01 23 45
2121
INTERNATIONAL,
2222

23-
// 003247012345
24-
EXTERNAL_CALL,
23+
// 003247012345
24+
EXTERNAL_CALL,
2525

26-
// 0473 01 23 45
27-
NATIONAL,
26+
// 0473 01 23 45
27+
NATIONAL,
2828

29-
// 0473012345
30-
NATIONAL_COMPACT,
29+
// 0473012345
30+
NATIONAL_COMPACT,
3131

32-
// 473012345
33-
NATIONAL_SHORT
32+
// 473012345
33+
NATIONAL_SHORT
3434
};
3535

3636
/**
@@ -42,7 +42,7 @@ enum phone_format {
4242
* @param formatted Number that will be formatted.
4343
* @return 0 if there is no issue, otherwise 1
4444
*/
45-
int num_format(char* number, char* country, enum phone_format type, char* formatted);
45+
int num_format(char *number, char *country, enum phone_format type, char *formatted);
4646

4747
#ifdef __cplusplus
4848
}

src/numinfo.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ using i18n::phonenumbers::PhoneNumber;
1313
using i18n::phonenumbers::PhoneNumberUtil;
1414
using i18n::phonenumbers::ShortNumberInfo;
1515

16-
int is_valid_number(char* number, char* country, int local, int short_code) {
16+
int is_valid_number(char *number, char *country, int local, int short_code) {
1717

18-
PhoneNumber num;
19-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
20-
const ShortNumberInfo& short_info = ShortNumberInfo();
18+
PhoneNumber num;
19+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
20+
const ShortNumberInfo &short_info = ShortNumberInfo();
2121
bool is_valid;
2222
bool is_valid_short_number;
23-
phone_util.Parse(number, country, &num);
23+
phone_util.Parse(number, country, &num);
2424

2525
if (local) {
2626
is_valid = phone_util.IsValidNumberForRegion(num, country);
@@ -39,10 +39,10 @@ int is_valid_number(char* number, char* country, int local, int short_code) {
3939
return (int) is_valid;
4040
}
4141

42-
int get_region(char* number, char* country, char *region) {
42+
int get_region(char *number, char *country, char *region) {
4343

4444
PhoneNumber num;
45-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
45+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
4646
phone_util.Parse(number, country, &num);
4747

4848
std::string r;
@@ -53,20 +53,20 @@ int get_region(char* number, char* country, char *region) {
5353
return 0;
5454
}
5555

56-
int get_country_code(char* number, char* country) {
56+
int get_country_code(char *number, char *country) {
5757

58-
PhoneNumber num;
59-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
60-
phone_util.Parse(number, country, &num);
58+
PhoneNumber num;
59+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
60+
phone_util.Parse(number, country, &num);
6161

62-
return (int) num.country_code();
62+
return (int) num.country_code();
6363
}
6464

65-
enum phone_type get_number_type(char* number, char* country) {
65+
enum phone_type get_number_type(char *number, char *country) {
6666

67-
PhoneNumber num;
68-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
69-
phone_util.Parse(number, country, &num);
67+
PhoneNumber num;
68+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
69+
phone_util.Parse(number, country, &num);
7070

71-
return (enum phone_type) phone_util.GetNumberType(num);
71+
return (enum phone_type) phone_util.GetNumberType(num);
7272
}

src/numinfo.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ extern "C" {
2828
#define GENERATE_STRING(STRING) #STRING,
2929

3030
enum phone_type {
31-
FOREACH_PHONE_TYPE(GENERATE_ENUM)
31+
FOREACH_PHONE_TYPE(GENERATE_ENUM)
3232
};
3333

3434
static const char *phone_type_str[] = {
35-
FOREACH_PHONE_TYPE(GENERATE_STRING)
35+
FOREACH_PHONE_TYPE(GENERATE_STRING)
3636
};
3737

3838
/**
@@ -47,7 +47,7 @@ static const char *phone_type_str[] = {
4747
* 2 Check if it's a short number or a classic number
4848
* @return 1 if the number is valid and 0 if it is invalid.
4949
*/
50-
int is_valid_number(char* number, char* country, int local, int short_code);
50+
int is_valid_number(char *number, char *country, int local, int short_code);
5151

5252
/**
5353
* Get the country based on the number's information.
@@ -57,7 +57,7 @@ int is_valid_number(char* number, char* country, int local, int short_code);
5757
* @param region Two-letter country (ISO 3166-1) of the number. If the software can't get the region ZZ, is returned.
5858
* @return 0 if there is no issue, otherwise 1
5959
*/
60-
int get_region(char* number, char* country, char *region);
60+
int get_region(char *number, char *country, char *region);
6161

6262
/**
6363
* Extract the country calling code of a number.
@@ -66,7 +66,7 @@ int get_region(char* number, char* country, char *region);
6666
* @param country Two-letter country (ISO 3166-1) where the national number will be taken into account.
6767
* @return Return the country calling code from the number.
6868
*/
69-
int get_country_code(char* number, char* country);
69+
int get_country_code(char *number, char *country);
7070

7171
/**
7272
* Get information about the nature of the phone number.
@@ -76,7 +76,7 @@ int get_country_code(char* number, char* country);
7676
* @return Return the type of number.
7777
* @see enum phone_type
7878
*/
79-
enum phone_type get_number_type(char* number, char* country);
79+
enum phone_type get_number_type(char *number, char *country);
8080

8181
#ifdef __cplusplus
8282
}

src/regioninfo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
using i18n::phonenumbers::PhoneNumberUtil;
77

8-
int get_country_code_for_region(char* region) {
8+
int get_country_code_for_region(char *region) {
99

10-
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
10+
const PhoneNumberUtil &phone_util = *PhoneNumberUtil::GetInstance();
1111

12-
return phone_util.GetCountryCodeForRegion(region);
12+
return phone_util.GetCountryCodeForRegion(region);
1313
}
1414

src/regioninfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
* @param region Two-letter country/region (ISO 3166-1) where the national number will be taken into account.
1313
* @return Return the country calling code from the region.
1414
*/
15-
int get_country_code_for_region(char* region);
15+
int get_country_code_for_region(char *region);
1616

1717
#ifdef __cplusplus
1818
}

0 commit comments

Comments
 (0)