Add apfl_string_eq macro
It's easy to forget the `== 0` after the apfl_string_cmp() call, so let's add a macro that does the job for us.
This commit is contained in:
parent
002894a960
commit
f685214abe
4 changed files with 11 additions and 10 deletions
|
|
@ -48,6 +48,7 @@ struct apfl_string_view apfl_string_view_from_string(struct apfl_string);
|
|||
int apfl_string_view_cmp(struct apfl_string_view, struct apfl_string_view);
|
||||
|
||||
#define apfl_string_cmp(a, b) apfl_string_view_cmp(apfl_string_view_from(a), apfl_string_view_from(b))
|
||||
#define apfl_string_eq(a, b) (apfl_string_cmp((a), (b)) == 0)
|
||||
|
||||
void apfl_string_deinit(struct apfl_string *);
|
||||
bool apfl_string_copy(struct apfl_string *dst, struct apfl_string_view src);
|
||||
|
|
|
|||
12
src/expr.c
12
src/expr.c
|
|
@ -801,7 +801,7 @@ const_eq(struct apfl_expr_const a, struct apfl_expr_const b)
|
|||
case APFL_EXPR_CONST_BOOLEAN:
|
||||
return a.boolean == b.boolean;
|
||||
case APFL_EXPR_CONST_STRING:
|
||||
return apfl_string_cmp(a.string, b.string) == 0;
|
||||
return apfl_string_eq(a.string, b.string);
|
||||
case APFL_EXPR_CONST_NUMBER:
|
||||
return a.number == b.number;
|
||||
}
|
||||
|
|
@ -819,7 +819,7 @@ param_eq(struct apfl_expr_param a, struct apfl_expr_param b)
|
|||
|
||||
switch (a.type) {
|
||||
case APFL_EXPR_PARAM_VAR:
|
||||
return apfl_string_cmp(a.var, b.var) == 0;
|
||||
return apfl_string_eq(a.var, b.var);
|
||||
case APFL_EXPR_PARAM_CONSTANT:
|
||||
return const_eq(a.constant, b.constant);
|
||||
case APFL_EXPR_PARAM_PREDICATE:
|
||||
|
|
@ -844,7 +844,7 @@ assignable_eq(struct apfl_expr_assignable a, struct apfl_expr_assignable b)
|
|||
|
||||
switch (a.type) {
|
||||
case APFL_EXPR_ASSIGNABLE_VAR:
|
||||
return apfl_string_cmp(a.var, b.var) == 0;
|
||||
return apfl_string_eq(a.var, b.var);
|
||||
case APFL_EXPR_ASSIGNABLE_CONSTANT:
|
||||
return const_eq(a.constant, b.constant);
|
||||
case APFL_EXPR_ASSIGNABLE_PREDICATE:
|
||||
|
|
@ -854,7 +854,7 @@ assignable_eq(struct apfl_expr_assignable a, struct apfl_expr_assignable b)
|
|||
return assignable_eq(*a.expand, *b.expand);
|
||||
case APFL_EXPR_ASSIGNABLE_DOT:
|
||||
return assignable_eq(*a.dot.lhs, *b.dot.lhs)
|
||||
&& apfl_string_cmp(a.dot.rhs, b.dot.rhs) == 0;
|
||||
&& apfl_string_eq(a.dot.rhs, b.dot.rhs);
|
||||
case APFL_EXPR_ASSIGNABLE_AT:
|
||||
return assignable_eq(*a.at.lhs, *b.at.lhs)
|
||||
&& apfl_expr_eq(*a.at.rhs, *b.at.rhs);
|
||||
|
|
@ -925,14 +925,14 @@ apfl_expr_eq(struct apfl_expr a, struct apfl_expr b)
|
|||
&& apfl_expr_eq(*a.assignment.rhs, *b.assignment.rhs);
|
||||
case APFL_EXPR_DOT:
|
||||
return apfl_expr_eq(*a.dot.lhs, *b.dot.lhs)
|
||||
&& apfl_string_cmp(a.dot.rhs, b.dot.rhs) == 0;
|
||||
&& apfl_string_eq(a.dot.rhs, b.dot.rhs);
|
||||
case APFL_EXPR_AT:
|
||||
return apfl_expr_eq(*a.at.lhs, *b.at.lhs)
|
||||
&& apfl_expr_eq(*a.at.rhs, *b.at.rhs);
|
||||
case APFL_EXPR_CONSTANT:
|
||||
return const_eq(a.constant, b.constant);
|
||||
case APFL_EXPR_VAR:
|
||||
return apfl_string_cmp(a.var, b.var) == 0;
|
||||
return apfl_string_eq(a.var, b.var);
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
|
|
|||
|
|
@ -1820,18 +1820,18 @@ parse_fragment(apfl_parser_ptr p, struct fragment *fragment, bool need, enum par
|
|||
fragment->position = p->token.position;
|
||||
break;
|
||||
case APFL_TOK_NAME:
|
||||
if (apfl_string_cmp(p->token.text, "nil") == 0) {
|
||||
if (apfl_string_eq(p->token.text, "nil")) {
|
||||
fragment->type = FRAG_CONSTANT;
|
||||
fragment->constant = (struct apfl_expr_const) {
|
||||
.type = APFL_EXPR_CONST_NIL,
|
||||
};
|
||||
} else if (apfl_string_cmp(p->token.text, "true") == 0) {
|
||||
} else if (apfl_string_eq(p->token.text, "true")) {
|
||||
fragment->type = FRAG_CONSTANT;
|
||||
fragment->constant = (struct apfl_expr_const) {
|
||||
.type = APFL_EXPR_CONST_BOOLEAN,
|
||||
.boolean = true,
|
||||
};
|
||||
} else if (apfl_string_cmp(p->token.text, "false") == 0) {
|
||||
} else if (apfl_string_eq(p->token.text, "false")) {
|
||||
fragment->type = FRAG_CONSTANT;
|
||||
fragment->constant = (struct apfl_expr_const) {
|
||||
.type = APFL_EXPR_CONST_BOOLEAN,
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ expect_text_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_
|
|||
{
|
||||
struct apfl_token tok;
|
||||
if (expect_token(tt, line, col, type, &tok)) {
|
||||
if (apfl_string_cmp(text, tok.text) != 0) {
|
||||
if (!apfl_string_eq(text, tok.text)) {
|
||||
test_failf(tt->t, "Token has wrong content. have=\"" APFL_STR_FMT "\", want=\"%s\"", APFL_STR_FMT_ARGS(tok.text), text);
|
||||
}
|
||||
apfl_token_deinit(&tok);
|
||||
|
|
|
|||
Loading…
Reference in a new issue