summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-10 23:08:17 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-10 23:14:08 +0430
commita5bc366d9a00a261e39e2968f03beb1245919e49 (patch)
treeb3614c4a1cbba7bb9830253cd4eb5770c1530e04 /Userland
parent11a8476cf42b6eaeef512f798fe61a222669078d (diff)
downloadserenity-a5bc366d9a00a261e39e2968f03beb1245919e49.zip
expr: Make Match expressions comply with POSIX
They should print the contents of capture group 1, if it exists.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/expr.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/Userland/Utilities/expr.cpp b/Userland/Utilities/expr.cpp
index 253adce1c9..38348d65a6 100644
--- a/Userland/Utilities/expr.cpp
+++ b/Userland/Utilities/expr.cpp
@@ -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();
}