changeset 131:3896861974ac

Added th_get_hex_triplet().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 17:02:35 +0300
parents 352ec3c300e4
children 10daf4660cae
files th_string.c th_string.h
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;
+}
+
+
--- 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
 }