From 687fa0ef362dfdacb6ee0a169d7ab0a84e747cc4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 8 Jan 2016 18:53:51 +0100 Subject: fixed copyright --- src/utils/mem.c | 2 +- src/utils/slist.c | 2 +- src/utils/strings.c | 2 +- src/utils/trie.c | 2 +- src/utils/utils.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/utils') diff --git a/src/utils/mem.c b/src/utils/mem.c index 7c5e0a2..693d555 100644 --- a/src/utils/mem.c +++ b/src/utils/mem.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/src/utils/slist.c b/src/utils/slist.c index 3d9b892..9753aa7 100644 --- a/src/utils/slist.c +++ b/src/utils/slist.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/src/utils/strings.c b/src/utils/strings.c index 40174a1..6f10d56 100644 --- a/src/utils/strings.c +++ b/src/utils/strings.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/src/utils/trie.c b/src/utils/trie.c index 72a62f6..b8c1e63 100644 --- a/src/utils/trie.c +++ b/src/utils/trie.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/src/utils/utils.h b/src/utils/utils.h index 5a1505b..49a7735 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. -- cgit v1.2.3-18-g5258 From f7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 14 Jan 2016 03:50:42 +0100 Subject: template-parser: added whitespace cleaners. needs more tests and docs --- src/utils/strings.c | 45 +++++++++++++++++++++++++++++++++++++-------- src/utils/utils.h | 2 ++ 2 files changed, 39 insertions(+), 8 deletions(-) (limited to 'src/utils') 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) { diff --git a/src/utils/utils.h b/src/utils/utils.h index 49a7735..dc67497 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -50,6 +50,8 @@ char* b_strdup_vprintf(const char *format, va_list ap); char* b_strdup_printf(const char *format, ...); bool b_str_starts_with(const char *str, const char *prefix); bool b_str_ends_with(const char *str, const char *suffix); +char* b_str_lstrip(char *str); +char* b_str_rstrip(char *str); char* b_str_strip(char *str); char** b_str_split(const char *str, char c, unsigned int max_pieces); char* b_str_replace(const char *str, const char search, const char *replace); -- cgit v1.2.3-18-g5258 From a8cde98ad6b747142ea1798f00a6b8c11b208709 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 14 Jan 2016 21:42:52 +0100 Subject: utils: string: strip form-feed and vertical-tab chars as whitespaces --- src/utils/strings.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/strings.c b/src/utils/strings.c index 846ae95..3151612 100644 --- a/src/utils/strings.c +++ b/src/utils/strings.c @@ -111,7 +111,8 @@ b_str_lstrip(char *str) 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] != '\r') && (str[i] != '\t') && (str[i] != '\f') && + (str[i] != '\v')) { str += i; break; @@ -134,7 +135,8 @@ b_str_rstrip(char *str) size_t str_len = strlen(str); for (i = str_len - 1; i >= 0; i--) { if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') && - (str[i] != '\r') && (str[i] != '\t')) + (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') && + (str[i] != '\v')) { str[i + 1] = '\0'; break; -- cgit v1.2.3-18-g5258