annotate libutil/digit_groups.c @ 261:a375639e4190

smpp-trx-sa: refactor time formatting code
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 11 Oct 2023 17:34:45 -0800
parents 28441920fb35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In version 2 of ThemWi owned number database, NANP numbers are stored as 3
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * uint16_t words: NPA, exchange and prefix, each uint16_t encoding a group of
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * 3 or 4 digits of the full telephone number. This library module provides
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * functions for turning groups of 3 or 4 digits into uint16_t words.
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 digits3_to_uint16(str)
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 char *str;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 int acc;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 acc = (str[0] - '0') * 100;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 acc += (str[1] - '0') * 10;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 acc += str[2] - '0';
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 return acc;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 }
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 digits4_to_uint16(str)
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *str;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int acc;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 acc = (str[0] - '0') * 1000;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 acc += (str[1] - '0') * 100;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 acc += (str[2] - '0') * 10;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 acc += str[3] - '0';
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return acc;
28441920fb35 beginning of number database version 2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }