expr: Make Match expressions comply with POSIX
They should print the contents of capture group 1, if it exists.
This commit is contained in:
parent
11a8476cf4
commit
a5bc366d9a
Notes:
sideshowbarker
2024-07-18 09:24:37 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/a5bc366d9a0 Pull-request: https://github.com/SerenityOS/serenity/pull/8617 Reviewed-by: https://github.com/linusg ✅
1 changed files with 8 additions and 5 deletions
|
@ -359,7 +359,12 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
virtual bool truth() const override { return integer() != 0; }
|
||||
virtual bool truth() const override
|
||||
{
|
||||
if (type() == Expression::Type::String)
|
||||
return !string().is_empty();
|
||||
return integer() != 0;
|
||||
}
|
||||
virtual int integer() const override
|
||||
{
|
||||
if (m_op == StringOperation::Substring || m_op == StringOperation::Match) {
|
||||
|
@ -411,10 +416,8 @@ private:
|
|||
return "";
|
||||
|
||||
StringBuilder result;
|
||||
for (auto& m : match.capture_group_matches) {
|
||||
for (auto& e : m)
|
||||
result.append(e.view.to_string());
|
||||
}
|
||||
for (auto& e : match.capture_group_matches[0])
|
||||
result.append(e.view.u8view());
|
||||
|
||||
return result.build();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue