diff options
author | Felix Buehler <account@buehler.rocks> | 2020-02-10 18:52:04 +0100 |
---|---|---|
committer | Felix Buehler <account@buehler.rocks> | 2020-02-10 21:05:18 +0100 |
commit | b5a804d1afaef1969de9c32060808fefb81a91e7 (patch) | |
tree | 2b03051f15bb30ae2c82321d856658af96d7245e /src/output.c | |
parent | eccd4a761817c791e702dbd60f16d36fae82cffe (diff) |
use format_placeholder for battery
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 |