aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/strings.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-01-14 03:50:42 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-01-14 03:50:42 +0100
commitf7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2 (patch)
tree9057cbd2b9eb61ec4bf57996b46d6faaf7844853 /src/utils/strings.c
parent5e53ba7406e65b51ec59aad634b6baf7154e1ad3 (diff)
downloadblogc-f7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2.tar.gz
blogc-f7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2.tar.bz2
blogc-f7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2.zip
template-parser: added whitespace cleaners. needs more tests and docs
Diffstat (limited to 'src/utils/strings.c')
-rw-r--r--src/utils/strings.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/utils/strings.c b/src/utils/strings.c
index 6f10d56..846ae95 100644
--- a/src/utils/strings.c
+++ b/src/utils/strings.c
@@ -103,22 +103,44 @@ b_str_ends_with(const char *str, const char *suffix)
char*
-b_str_strip(char *str)
+b_str_lstrip(char *str)
{
if (str == NULL)
- return str;
+ return NULL;
+ int i;
+ size_t str_len = strlen(str);
+ for (i = 0; i < str_len; i++) {
+ if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
+ (str[i] != '\r') && (str[i] != '\t'))
+ {
+ str += i;
+ break;
+ }
+ if (i == str_len - 1) {
+ str += str_len;
+ break;
+ }
+ }
+ return str;
+}
+
+
+char*
+b_str_rstrip(char *str)
+{
+ if (str == NULL)
+ return NULL;
int i;
size_t str_len = strlen(str);
for (i = str_len - 1; i >= 0; i--) {
- if (!isspace(str[i])) {
+ if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
+ (str[i] != '\r') && (str[i] != '\t'))
+ {
str[i + 1] = '\0';
break;
}
- }
- str_len = strlen(str);
- for (i = 0; i < str_len; i++) {
- if (!isspace(str[i])) {
- str = str + i;
+ if (i == 0) {
+ str[0] = '\0';
break;
}
}
@@ -126,6 +148,13 @@ b_str_strip(char *str)
}
+char*
+b_str_strip(char *str)
+{
+ return b_str_lstrip(b_str_rstrip(str));
+}
+
+
char**
b_str_split(const char *str, char c, unsigned int max_pieces)
{