changeset 174:7d5707438333

Comments, cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 05:34:48 +0200
parents 503f0cb98775
children 3d0a1f87e393
files th_string.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Mon Feb 23 15:45:12 2015 +0200
+++ b/th_string.c	Sun Mar 01 05:34:48 2015 +0200
@@ -49,7 +49,9 @@
 }
 
 
-/* Like strdup, but trims whitespace from stringImplementation of strdup() with a NULL check
+/* Like strdup, but trims whitespace from the string
+ * according to specified flags. See TH_TRIM_* in
+ * th_string.h
  */
 char *th_strdup_trim(const char *s, const int flags)
 {
@@ -59,16 +61,20 @@
         return NULL;
 
     len = strlen(s);
+
+    // Trim start: find first non-whitespace character
     if (flags & TH_TRIM_START)
         for (start = 0; start < len && th_isspace(s[start]); start++);
     else
         start = 0;
-    
+
+    // Trim end: find last non-whitespace character
     if (flags & TH_TRIM_END)
         for (end = len; end > start && th_isspace(s[end]); end--);
     else
         end = len;
 
+    // Allocate memory for result
     len = end - start + 1;
     if ((res = th_malloc(len + 1)) == NULL)
         return NULL;
@@ -556,12 +562,14 @@
             val *= 16;
             val += (*p - '0');
         }
-        else if (*p >= 'A' && *p <= 'F')
+        else
+        if (*p >= 'A' && *p <= 'F')
         {
             val *= 16;
             val += (*p - 'A') + 10;
         }
-        else if (*p >= 'a' && *p <= 'f')
+        else
+        if (*p >= 'a' && *p <= 'f')
         {
             val *= 16;
             val += (*p - 'a') + 10;