Skip to content

Commit

Permalink
Settle on case insensitive for templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsdz committed Nov 25, 2024
1 parent a405b61 commit 0925a3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions man/lowdown.1
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,8 @@ Templates control statements are delimited as
.Li $statement$
or
.Li ${statement} .
Arbitrary white-space may surround the statement between matching
delimiters.
Arbitrary white-space may surround the case-insensitive statement
between matching delimiters.
Empty statements are stripped, with the exception of
.Li $$ ,
which outputs a literal
Expand Down Expand Up @@ -833,7 +833,7 @@ Expressions consist of
.Li initial[.transform]* ,
with
.Li initial
being a metadata key,
being a canonicalisd metadata key,
.Li this
.Pq value of a current loop context ,
or
Expand Down
24 changes: 12 additions & 12 deletions template.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@ op_queue(struct opq *q, struct op **cop, const char *str, size_t sz)
{
/* TODO: space before "(". */

if (sz > 7 && strncmp(str, "ifdef(", 6) == 0 &&
if (sz > 7 && strncasecmp(str, "ifdef(", 6) == 0 &&
str[sz - 1] == ')')
return op_queue_ifdef(q, cop, str + 6, sz - 7);
if (sz > 5 && strncmp(str, "for(", 4) == 0 &&
if (sz > 5 && strncasecmp(str, "for(", 4) == 0 &&
str[sz - 1] == ')')
return op_queue_for(q, cop, str + 4, sz - 5);
if (sz == 4 && strncmp(str, "else", 4) == 0)
if (sz == 4 && strncasecmp(str, "else", 4) == 0)
return op_queue_else(q, cop);
if (sz == 5 && strncmp(str, "endif", 5) == 0)
if (sz == 5 && strncasecmp(str, "endif", 5) == 0)
return op_queue_endif(cop);
if (sz == 6 && strncmp(str, "endfor", 6) == 0)
if (sz == 6 && strncasecmp(str, "endfor", 6) == 0)
return op_queue_endfor(cop);

return op_queue_expr(q, *cop, str, sz);
Expand Down Expand Up @@ -442,13 +442,13 @@ op_eval_function(const char *expr, size_t sz,
{
struct op_resq *nq;

if (sz == 9 && strncmp(expr, "uppercase", 9) == 0)
if (sz == 9 && strncasecmp(expr, "uppercase", 9) == 0)
nq = op_eval_function_uppercase(mq, input);
else if (sz == 9 && strncmp(expr, "lowercase", 9) == 0)
else if (sz == 9 && strncasecmp(expr, "lowercase", 9) == 0)
nq = op_eval_function_lowercase(mq, input);
else if (sz == 5 && strncmp(expr, "split", 5) == 0)
else if (sz == 5 && strncasecmp(expr, "split", 5) == 0)
nq = op_eval_function_split(mq, input);
else if (sz == 4 && strncmp(expr, "trim", 4) == 0)
else if (sz == 4 && strncasecmp(expr, "trim", 4) == 0)
nq = op_resq_clone(input, 1);
else if ((nq = malloc(sizeof(struct op_resq))) != NULL)
TAILQ_INIT(nq);
Expand All @@ -471,16 +471,16 @@ op_eval_initial(const char *expr, size_t sz, const char *this,

TAILQ_INIT(q);

if (sz == 4 && strncmp(expr, "this", sz) == 0) {
if (sz == 4 && strncasecmp(expr, "this", sz) == 0) {
v = this;
vsz = this == NULL ? 0 : strlen(this);
} else if (sz == 4 && strncmp(expr, "body", sz) == 0) {
} else if (sz == 4 && strncasecmp(expr, "body", sz) == 0) {
v = content->data;
vsz = content->size;
} else
TAILQ_FOREACH(m, mq, entries)
if (strlen(m->key) == sz &&
strncmp(m->key, expr, sz) == 0) {
strncasecmp(m->key, expr, sz) == 0) {
v = m->value;
vsz = strlen(m->value);
break;
Expand Down

0 comments on commit 0925a3e

Please sign in to comment.