chiark / gitweb /
string-util: put together strstrip() from skip_leading_chars() and delete_trailing_ch...
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Jun 2018 09:58:38 +0000 (11:58 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
src/basic/string-util.c

index b53686a1162a7805cf398a3a9e2eeb02f621f7d3..13456f101454846a8e021fe37099df79371740a7 100644 (file)
@@ -269,23 +269,12 @@ char *strjoin_real(const char *x, ...) {
 }
 
 char *strstrip(char *s) {
-        char *e;
-
         if (!s)
                 return NULL;
 
-        /* Drops trailing whitespace. Modifies the string in
-         * place. Returns pointer to first non-space character */
+        /* Drops trailing whitespace. Modifies the string in place. Returns pointer to first non-space character */
 
-        s += strspn(s, WHITESPACE);
-
-        for (e = strchr(s, 0); e > s; e --)
-                if (!strchr(WHITESPACE, e[-1]))
-                        break;
-
-        *e = 0;
-
-        return s;
+        return delete_trailing_chars(skip_leading_chars(s, WHITESPACE), WHITESPACE);
 }
 
 #if 0 /// UNNEEDED by elogind