core/weather/wx_label.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file wx_label.c | ||
| 3 | * @brief The short word a small slot shows for the sky. | ||
| 4 | * | ||
| 5 | * @ingroup lib_core | ||
| 6 | */ | ||
| 7 | #include "weather/wx_label.h" | ||
| 8 | |||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | #define NIGHT_SUFFIX "_NIGHT" ///< What the phone adds to a token after dark | ||
| 12 | #define NIGHT_SUFFIX_LEN 6 ///< The suffix's length, without its terminator | ||
| 13 | |||
| 14 | 5 | void wx_label_short(char *out, size_t n, const char *condition) | |
| 15 | { | ||
| 16 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (n == 0) |
| 17 | { | ||
| 18 | ✗ | return; | |
| 19 | } | ||
| 20 | |||
| 21 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
5 | if (!condition || !condition[0]) |
| 22 | { | ||
| 23 | 1 | condition = "UNKNOWN"; | |
| 24 | } | ||
| 25 | |||
| 26 | 5 | size_t len = strlen(condition); | |
| 27 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 time.
|
5 | if (len > NIGHT_SUFFIX_LEN && !strcmp(condition + len - NIGHT_SUFFIX_LEN, NIGHT_SUFFIX)) |
| 28 | { | ||
| 29 | 2 | len -= NIGHT_SUFFIX_LEN; | |
| 30 | } | ||
| 31 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
|
5 | if (len >= n) |
| 32 | { | ||
| 33 | 1 | len = n - 1; | |
| 34 | } | ||
| 35 | |||
| 36 | 5 | memcpy(out, condition, len); | |
| 37 | 5 | out[len] = '\0'; | |
| 38 | } | ||
| 39 |