# HG changeset patch # User Matti Hamalainen # Date 1425180888 -7200 # Node ID 7d57074383332f786578d635350d469f713f32dc # Parent 503f0cb98775cd0eaabb5411a496c47824b36051 Comments, cosmetics. diff -r 503f0cb98775 -r 7d5707438333 th_string.c --- 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;