From b5a804d1afaef1969de9c32060808fefb81a91e7 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Mon, 10 Feb 2020 18:52:04 +0100 Subject: use format_placeholder for battery --- src/output.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/output.c') 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 #include #include +#include #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 -- cgit v1.2.3