diff options
Diffstat (limited to 'src/output.c')
-rw-r--r-- | src/output.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/output.c b/src/output.c index 937fa60..9a18049 100644 --- a/src/output.c +++ b/src/output.c @@ -8,6 +8,7 @@ #include <sys/types.h> #include <fcntl.h> #include <dirent.h> +#include <ctype.h> #include "i3status.h" @@ -121,3 +122,36 @@ void maybe_escape_markup(char *text, char **buffer) { } } } + +/* + * remove leading spaces + */ +char *ltrim(const char *s) { + while (isspace(*s)) + ++s; + return sstrdup(s); +} + +/* + * remove trailing spaces + */ +char *rtrim(const char *s) { + char *r = sstrdup(s); + if (r != NULL) { + char *fr = r + strlen(s) - 1; + while ((isspace(*fr) || *fr == 0) && fr >= r) + --fr; + *++fr = 0; + } + return r; +} + +/* + * remove leading & trailing spaces + */ +char *trim(const char *s) { + char *r = rtrim(s); + char *f = ltrim(r); + free(r); + return f; +}
\ No newline at end of file |