aboutsummaryrefslogtreecommitdiff
path: root/sway/stringop.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/stringop.c')
-rw-r--r--sway/stringop.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/sway/stringop.c b/sway/stringop.c
index 00cc32b8..1dff97bf 100644
--- a/sway/stringop.c
+++ b/sway/stringop.c
@@ -1,38 +1,37 @@
+#include "stringop.h"
#include <stdlib.h>
#include <stdio.h>
-#include <strings.h>
-#include <ctype.h>
-#include "stringop.h"
#include "string.h"
#include "list.h"
+#include <strings.h>
/* Note: This returns 8 characters for trimmed_start per tab character. */
-void strip_whitespace(char *str) {
- int shift = 0;
- int bpair = 1;
- int in_str = 0, in_ch = 0;
- while (*str) {
- str[-shift] = str[0];
- if (*str == '"' && !in_ch) {
- in_str = !in_str;
- } else if (*str == '\'' && !in_str) {
- in_ch = !in_ch;
- } else if (!in_ch && !in_str) {
- if (isblank(*str)) {
- if (bpair) {
- ++shift;
- }
- bpair=1;
- } else {
- bpair = 0;
- }
+char *strip_whitespace(char *_str, int *trimmed_start) {
+ *trimmed_start = 0;
+ if (*_str == '\0')
+ return _str;
+ char *strold = _str;
+ while (*_str == ' ' || *_str == '\t') {
+ if (*_str == '\t') {
+ *trimmed_start += 8;
+ } else {
+ *trimmed_start += 1;
}
- ++str;
+ _str++;
}
- str[-shift-bpair] = 0;
+ char *str = malloc(strlen(_str) + 1);
+ strcpy(str, _str);
+ free(strold);
+ int i;
+ for (i = 0; str[i] != '\0'; ++i);
+ do {
+ i--;
+ } while (i >= 0 && (str[i] == ' ' || str[i] == '\t'));
+ str[i + 1] = '\0';
+ return str;
}
-void strip_comments(char *str) {
+char *strip_comments(char *str) {
int in_string = 0, in_character = 0;
int i = 0;
while (str[i] != '\0') {
@@ -41,13 +40,14 @@ void strip_comments(char *str) {
} else if (str[i] == '\'' && !in_string) {
in_character = !in_character;
} else if (!in_character && !in_string) {
- if (str[i] == '#') {
+ if (str[i] == '#' && i == 0) {
str[i] = '\0';
break;
}
}
++i;
}
+ return str;
}
list_t *split_string(const char *str, const char *delims) {