Mercurial > hg > th-libs
changeset 497:ff3ebe22f6c5
Change int th_get_hex_triplet(const char *str) API to
BOOL th_get_hex_triplet(const char *str, unsigned int *value).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 25 Dec 2019 11:00:51 +0200 |
parents | 8c837a33cfb6 |
children | 1dbd9259c3b8 |
files | th_config.c th_string.c th_string.h |
diffstat | 3 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/th_config.c Wed Dec 25 08:38:11 2019 +0200 +++ b/th_config.c Wed Dec 25 11:00:51 2019 +0200 @@ -507,7 +507,7 @@ switch (item->type) { case ITEM_HEX_TRIPLET: - *(item->v.val_int) = th_get_hex_triplet(tmpStr); + th_get_hex_triplet(tmpStr, item->v.val_uint); prevMode = parseMode; parseMode = PM_IDLE; break;
--- a/th_string.c Wed Dec 25 08:38:11 2019 +0200 +++ b/th_string.c Wed Dec 25 11:00:51 2019 +0200 @@ -978,35 +978,36 @@ #include "th_strmatch.c" -int th_get_hex_triplet(const char *str) +BOOL th_get_hex_triplet(const char *str, unsigned int *value) { const char *p = str; - int len, val = 0; + int len; + *value = 0; for (len = 0; *p && len < 6; p++, len++) { if (*p >= '0' && *p <= '9') { - val *= 16; - val += (*p - '0'); + (*value) *= 16; + (*value) += (*p - '0'); } else if (*p >= 'A' && *p <= 'F') { - val *= 16; - val += (*p - 'A') + 10; + (*value) *= 16; + (*value) += (*p - 'A') + 10; } else if (*p >= 'a' && *p <= 'f') { - val *= 16; - val += (*p - 'a') + 10; + (*value) *= 16; + (*value) += (*p - 'a') + 10; } else - return -1; + return FALSE; } - return (len == 6) ? val : -1; + return (len == 6); }
--- a/th_string.h Wed Dec 25 08:38:11 2019 +0200 +++ b/th_string.h Wed Dec 25 11:00:51 2019 +0200 @@ -158,7 +158,7 @@ BOOL th_strmatch(const char *haystack, const char *pattern); BOOL th_strcasematch(const char *haystack, const char *pattern); -int th_get_hex_triplet(const char *str); +BOOL th_get_hex_triplet(const char *str, unsigned int *value); BOOL th_get_boolean(const char *str, BOOL *value); BOOL th_get_int(const char *str, unsigned int *value, BOOL *neg);