mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibSQL: Add simple REGEXP match
The implementation of LIKE uses regexes under the hood, and this implementation of REGEXP takes the same approach. It employs PosixExtended from LibRegex with case insensitive and Unicode flags set. The implementation of LIKE is based on SQLlite specs, but SQLlite does not offer directions for a built-in regex functionality, so this one uses LibRegex.
This commit is contained in:
parent
ace36681ff
commit
66216d3af6
Notes:
sideshowbarker
2024-07-17 20:22:42 +09:00
Author: https://github.com/mnlrsn 🔰
Commit: 66216d3af6
Pull-request: https://github.com/SerenityOS/serenity/pull/12050
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 80 additions and 1 deletions
|
@ -242,9 +242,26 @@ Value MatchExpression::evaluate(ExecutionContext& context) const
|
|||
auto result = regex.match(lhs_value.to_string(), PosixFlags::Insensitive | PosixFlags::Unicode);
|
||||
return Value(invert_expression() ? !result.success : result.success);
|
||||
}
|
||||
case MatchOperator::Regexp: {
|
||||
Value lhs_value = lhs()->evaluate(context);
|
||||
Value rhs_value = rhs()->evaluate(context);
|
||||
|
||||
auto regex = Regex<PosixExtended>(rhs_value.to_string());
|
||||
auto err = regex.parser_result.error;
|
||||
if (err != regex::Error::NoError) {
|
||||
StringBuilder builder;
|
||||
builder.append("Regular expression: ");
|
||||
builder.append(get_error_string(err));
|
||||
|
||||
context.result->set_error(SQLErrorCode::SyntaxError, builder.build());
|
||||
return Value(false);
|
||||
}
|
||||
|
||||
auto result = regex.match(lhs_value.to_string(), PosixFlags::Insensitive | PosixFlags::Unicode);
|
||||
return Value(invert_expression() ? !result.success : result.success);
|
||||
}
|
||||
case MatchOperator::Glob:
|
||||
case MatchOperator::Match:
|
||||
case MatchOperator::Regexp:
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue