core/wire/coords.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file coords.c | ||
| 3 | * @brief Telling a real fix from the phone's way of saying it has none. | ||
| 4 | * | ||
| 5 | * @ingroup lib_core | ||
| 6 | */ | ||
| 7 | #include "wire/coords.h" | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @brief Whether a string carries at least one digit. | ||
| 11 | * | ||
| 12 | * A digit is the whole tell, so this walks for one rather than calling strpbrk. The tree has one | ||
| 13 | * other caller of that family and it drags a few hundred bytes of libc in behind it. | ||
| 14 | * | ||
| 15 | * @param s The string to check, or NULL. | ||
| 16 | * @return Whether it holds a digit. | ||
| 17 | */ | ||
| 18 | 16 | static bool has_digit(const char *s) | |
| 19 | { | ||
| 20 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
|
16 | if (!s) |
| 21 | { | ||
| 22 | 2 | return false; | |
| 23 | } | ||
| 24 | |||
| 25 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 5 times.
|
31 | for (; *s; s++) |
| 26 | { | ||
| 27 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 12 times.
|
26 | if (*s >= '0' && *s <= '9') |
| 28 | { | ||
| 29 | 9 | return true; | |
| 30 | } | ||
| 31 | } | ||
| 32 | 5 | return false; | |
| 33 | } | ||
| 34 | |||
| 35 | 10 | bool coords_look_real(const char *lat, const char *lon) | |
| 36 | { | ||
| 37 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
|
10 | return has_digit(lat) && has_digit(lon); |
| 38 | } | ||
| 39 |