]> git.mdlowis.com Git - proto/labwc.git/commitdiff
string-helpers: rtrim() with just char *s, call it later in string_strip
authorTomi Ollila <tomi.ollila@iki.fi>
Wed, 1 Jan 2025 19:26:57 +0000 (21:26 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 16 Mar 2025 11:18:39 +0000 (11:18 +0000)
char **s not needed to get trailing whitespace trimmed,
and rtrim() does not return anything

if there is leading whitespace in *s in call to string_strip(),
there is less chars left to scan in rtrim().

src/common/string-helpers.c

index ef29c33982452a258055d7d9d4de32ecc815ac9c..f753d1a1e0266b458a728b7e64032e0117dd1c8d 100644 (file)
@@ -30,14 +30,14 @@ trim_last_field(char *buf, char delim)
 }
 
 static void
-rtrim(char **s)
+rtrim(char *s)
 {
-       size_t len = strlen(*s);
+       size_t len = strlen(s);
        if (!len) {
                return;
        }
-       char *end = *s + len - 1;
-       while (end >= *s && isspace(*end)) {
+       char *end = s + len - 1;
+       while (end >= s && isspace(*end)) {
                end--;
        }
        *(end + 1) = '\0';
@@ -46,10 +46,10 @@ rtrim(char **s)
 char *
 string_strip(char *s)
 {
-       rtrim(&s);
        while (isspace(*s)) {
                s++;
        }
+       rtrim(s);
        return s;
 }