Skip to content

Commit

Permalink
karm-io: fix Re::negate, update gitignore for intelliJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Louciole committed Mar 27, 2024
1 parent c5c1bba commit 282f774
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ __pycache__/
.python-version
book/
*.code-workspace
.idea/
skift.iml
10 changes: 9 additions & 1 deletion src/libs/karm-io/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ auto operator&(Expr auto a, Expr auto b) {
/// Inverts the result of the expression.
inline auto negate(Expr auto expr) {
return [=](auto &scan) {
return not expr(scan);
auto saved = scan;
if (not expr(scan)) {
if (scan.ended())
return false;
scan.next();
return true;
}
scan = saved;
return false;
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/libs/karm-io/tests/text-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ test$(exprSingle) {
return Ok();
}

test$(exprNegate) {
expect$(Re::match(~'a'_re, "") == Match::NO);
expect$(Re::match(~'a'_re, "b") == Match::YES);
expect$(Re::match(~'a'_re, "a") == Match::NO);
expect$(Re::match((~'a'_re) & 'a'_re, "ba") == Match::YES);
expect$(Re::match((~'a'_re) & 'a'_re, "aa") == Match::NO);

return Ok();
}

} // namespace Karm::Io::Tests

0 comments on commit 282f774

Please sign in to comment.