FreeCalypso > hg > themwi-nanp
annotate libnumutil/digit_groups.c @ 11:3d6cfb615d90
add make install hierarchy
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Dec 2023 05:16:12 +0000 |
parents | 159dd90eeafe |
children |
rev | line source |
---|---|
0
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In version 2 of ThemWi owned number database, NANP numbers are stored as 3 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * uint16_t words: NPA, exchange and prefix, each uint16_t encoding a group of |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * 3 or 4 digits of the full telephone number. This library module provides |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * functions for turning groups of 3 or 4 digits into uint16_t words. |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <themwi/nanp/number_utils.h> |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 uint16_t digits3_to_uint16(const char *str) |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 int acc; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 acc = (str[0] - '0') * 100; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 acc += (str[1] - '0') * 10; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 acc += str[2] - '0'; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return acc; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 } |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 uint16_t digits4_to_uint16(const char *str) |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int acc; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 acc = (str[0] - '0') * 1000; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 acc += (str[1] - '0') * 100; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 acc += (str[2] - '0') * 10; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 acc += str[3] - '0'; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return acc; |
159dd90eeafe
beginning, libnumutil compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |