# HG changeset patch # User Matti Hamalainen # Date 1288447355 -10800 # Node ID 3896861974acb051c0bb8ca050dc1adce7243aee # Parent 352ec3c300e48227787c11d74ff6c14aed33f5c6 Added th_get_hex_triplet(). diff -r 352ec3c300e4 -r 3896861974ac th_string.c --- a/th_string.c Sat Oct 30 15:19:34 2010 +0300 +++ b/th_string.c Sat Oct 30 17:02:35 2010 +0300 @@ -418,3 +418,24 @@ return didMatch; } + +int th_get_hex_triplet(const char *str) +{ + const char *p = str; + int len, val = 0; + + for (len = 0; *p && len < 6; p++, len++) { + if (*p >= '0' && *p <= '9') { + val *= 16; val += (*p - '0'); + } else if (*p >= 'A' && *p <= 'F') { + val *= 16; val += (*p - 'A') + 10; + } else if (*p >= 'a' && *p <= 'f') { + val *= 16; val += (*p - 'a') + 10; + } else + return -1; + } + + return (len == 6) ? val : -1; +} + + diff -r 352ec3c300e4 -r 3896861974ac th_string.h --- a/th_string.h Sat Oct 30 15:19:34 2010 +0300 +++ b/th_string.h Sat Oct 30 17:02:35 2010 +0300 @@ -61,6 +61,7 @@ BOOL th_strmatch(const char *, const char *); BOOL th_strcasematch(const char *, const char *); +int th_get_hex_triplet(const char *); #ifdef __cplusplus }