aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc/template-parser.c31
-rw-r--r--src/common/utils.c8
-rw-r--r--src/common/utils.h1
3 files changed, 24 insertions, 16 deletions
diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c
index c3e9a5c..a53f1aa 100644
--- a/src/blogc/template-parser.c
+++ b/src/blogc/template-parser.c
@@ -161,7 +161,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
state = TEMPLATE_BLOCK_START;
case TEMPLATE_BLOCK_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'a' && c <= 'z') {
state = TEMPLATE_BLOCK_TYPE;
@@ -183,7 +183,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_BLOCK_TYPE:
if (c >= 'a' && c <= 'z')
break;
- if (c == ' ') {
+ if (bc_isspace(c)) {
if ((current - start == 5) &&
(0 == strncmp("block", src + start, 5)))
{
@@ -339,7 +339,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_BLOCK_TYPE_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'a' && c <= 'z') {
state = TEMPLATE_BLOCK_BLOCK_TYPE;
@@ -354,7 +354,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_BLOCK_BLOCK_TYPE:
if ((c >= 'a' && c <= 'z') || c == '_')
break;
- if (c == ' ') {
+ if (bc_isspace(c)) {
if ((current - start == 5) &&
(0 == strncmp("entry", src + start, 5)))
{
@@ -387,7 +387,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_IF_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_IF_VARIABLE;
@@ -402,7 +402,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_BLOCK_IF_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (c == ' ') {
+ if (bc_isspace(c)) {
end = current;
if (type == BLOGC_TEMPLATE_NODE_IF)
state = TEMPLATE_BLOCK_IF_OPERATOR_START;
@@ -417,22 +417,21 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_IF_OPERATOR_START:
- if (c == ' ') {
+ if (bc_isspace(c))
break;
- }
state = TEMPLATE_BLOCK_IF_OPERATOR;
op_start = current;
break;
case TEMPLATE_BLOCK_IF_OPERATOR:
- if (c != ' ')
+ if (!bc_isspace(c))
break;
state = TEMPLATE_BLOCK_IF_OPERAND_START;
op_end = current;
break;
case TEMPLATE_BLOCK_IF_OPERAND_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_IF_VARIABLE_OPERAND;
@@ -469,7 +468,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_FOREACH_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_FOREACH_VARIABLE;
@@ -485,7 +484,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_BLOCK_FOREACH_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (c == ' ') {
+ if (bc_isspace(c)) {
end = current;
state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER;
break;
@@ -497,7 +496,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_END_WHITESPACE_CLEANER:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c == '-') {
lstrip_next = true;
@@ -524,7 +523,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_VARIABLE_START:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_VARIABLE;
@@ -540,7 +539,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (c == ' ') {
+ if (bc_isspace(c)) {
end = current;
state = TEMPLATE_VARIABLE_END;
break;
@@ -557,7 +556,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_VARIABLE_END:
- if (c == ' ')
+ if (bc_isspace(c))
break;
if (c == '}') {
state = TEMPLATE_CLOSE_BRACKET;
diff --git a/src/common/utils.c b/src/common/utils.c
index 530ab6c..692d1ce 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -167,6 +167,14 @@ bc_strdup_printf(const char *format, ...)
}
+// locale-independent implementation of isspace
+bool
+bc_isspace(int c)
+{
+ return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
+}
+
+
bool
bc_str_starts_with(const char *str, const char *prefix)
{
diff --git a/src/common/utils.h b/src/common/utils.h
index bc3a157..94c3356 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -42,6 +42,7 @@ char* bc_strdup(const char *s);
char* bc_strndup(const char *s, size_t n);
char* bc_strdup_vprintf(const char *format, va_list ap);
char* bc_strdup_printf(const char *format, ...);
+bool bc_isspace(int c);
bool bc_str_starts_with(const char *str, const char *prefix);
bool bc_str_ends_with(const char *str, const char *suffix);
char* bc_str_lstrip(char *str);