diff th_string.c @ 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 8917c39ef6c5
children 12dbe0102d72
line wrap: on
line diff
--- 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);
 }