From 7a36499f22f59d13d75790ca66792229561cb3a8 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 23 Nov 2016 17:10:06 -0300 Subject: [PATCH] Makes @pm compatible with the brand new capture schema --- src/operators/pm.cc | 12 +++++++++++- src/operators/pm.h | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/operators/pm.cc b/src/operators/pm.cc index 35fa033e..b6354e50 100644 --- a/src/operators/pm.cc +++ b/src/operators/pm.cc @@ -88,7 +88,8 @@ void Pm::replaceAll(std::string str, const std::string& from, } } -bool Pm::evaluate(Transaction *transaction, const std::string &input) { +bool Pm::evaluate(Transaction *transaction, Rule *rule, + const std::string &input) { int rc = 0; ACMPT pt; pt.parser = m_p; @@ -96,10 +97,19 @@ bool Pm::evaluate(Transaction *transaction, const std::string &input) { const char *match = NULL; rc = acmp_process_quick(&pt, &match, input.c_str(), input.length()); + bool capture = rule && rule->getActionsByName("capture").size() > 0; + if (rc == 1 && transaction) { transaction->m_matched.push_back(std::string(match)); } + if (capture && transaction && rc) { + transaction->m_collections.storeOrUpdateFirst("TX", "0", + std::string(match)); + transaction->debug(7, "Added pm match TX.0: " + \ + std::string(match)); + } + return rc == 1; } diff --git a/src/operators/pm.h b/src/operators/pm.h index 1ab2b389..9c0562fb 100644 --- a/src/operators/pm.h +++ b/src/operators/pm.h @@ -37,7 +37,12 @@ class Pm : public Operator { ~Pm(); void replaceAll(std::string str, const std::string& from, const std::string& to); - bool evaluate(Transaction *transaction, const std::string &input) override; + bool evaluate(Transaction *transaction, Rule *rule, + const std::string &input) override; + bool evaluate(Transaction *transaction, + const std::string &input) override { + return evaluate(transaction, NULL, input); + } bool init(const std::string &file, std::string *error) override; void postOrderTraversal(acmp_btree_node_t *node);