summaryrefslogtreecommitdiff
path: root/src/output.c
diff options
context:
space:
mode:
authorIngo Bürk <admin@airblader.de>2020-02-17 08:30:44 +0100
committerGitHub <noreply@github.com>2020-02-17 08:30:44 +0100
commit5b115d39f85c5575b8ef6b888c8a66dfc883e603 (patch)
tree2b03051f15bb30ae2c82321d856658af96d7245e /src/output.c
parenteccd4a761817c791e702dbd60f16d36fae82cffe (diff)
parentb5a804d1afaef1969de9c32060808fefb81a91e7 (diff)
Merge pull request #380 from Stunkymonkey/percent-split
use format_placeholder(i3lib) for battery_info
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c34
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