aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-03-18 22:13:13 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-03-22 22:20:26 -0400
commit25e98c6d2bcf1a17484a2953329ffcfffbb169b2 (patch)
treecc9fc33d63f14bea94f442cdcf3c2479b7990988 /src/utils.c
parent8ef322421ae938103881c5f90d81265ca0bc39c2 (diff)
downloadstasis-25e98c6d2bcf1a17484a2953329ffcfffbb169b2.tar.gz
Move collapse_whitespace to utils.c / utils.h
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 941923a..74b4f6f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -647,3 +647,28 @@ int fix_tox_conf(const char *filename, char **result) {
ini_free(&toxini);
return 0;
}
+
+static size_t count_blanks(char *s) {
+ size_t blank = 0;
+ for (size_t i = 0; i < strlen(s); i++) {
+ if (isblank(s[i])) {
+ blank++;
+ } else {
+ break;
+ }
+ }
+ return blank;
+}
+
+char *collapse_whitespace(char **s) {
+ char *x = (*s);
+ size_t len = strlen(x);
+ for (size_t i = 0; i < len; i++) {
+ size_t blank = count_blanks(&x[i]);
+ if (blank > 1) {
+ memmove(&x[i], &x[i] + blank, strlen(&x[i]));
+ }
+ }
+
+ return *s;
+}