Sfoglia il codice sorgente

expr: Make Match expressions comply with POSIX

They should print the contents of capture group 1, if it exists.
Ali Mohammad Pur 4 anni fa
parent
commit
a5bc366d9a
1 ha cambiato i file con 8 aggiunte e 5 eliminazioni
  1. 8 5
      Userland/Utilities/expr.cpp

+ 8 - 5
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();
             }