From 86508c9dc4e4280131595470b96d5bd4a16d864c Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Wed, 12 Jan 2011 18:31:31 +0100
Subject: [PATCH] Delete action: leaving lexemes that do not meet a condition.

---
 libwccl/ops/actions/delete.cpp | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libwccl/ops/actions/delete.cpp b/libwccl/ops/actions/delete.cpp
index 6deb051..e6b8b3e 100644
--- a/libwccl/ops/actions/delete.cpp
+++ b/libwccl/ops/actions/delete.cpp
@@ -1,5 +1,6 @@
 #include <libwccl/ops/actions/delete.h>
 #include <libwccl/ops/functions/constant.h>
+#include <libpwrutils/foreach.h>
 #include <sstream>
 
 namespace Wccl {
@@ -7,7 +8,23 @@ namespace Wccl {
 Bool Delete::execute(const ActionExecContext& context) const
 {
 	Bool changed(false);
-	//@todo: implement
+	const boost::shared_ptr<const Position> pos = pos_->apply(context);
+	int abs_pos = context.sentence_context().get_abs_position(*pos);
+	if (context.sentence_context().is_inside(abs_pos)) {
+		Corpus2::Token& token = *context.sentence_context().at(abs_pos);
+		std::vector<Corpus2::Lexeme> original(token.lexemes());
+		std::vector<Corpus2::Lexeme> remaining;
+		token.lexemes() = remaining;
+		foreach (const Corpus2::Lexeme& lexeme, original) {
+			token.add_lexeme(lexeme);
+			if (!condition_->apply(context)->get_value()) {
+				remaining.push_back(lexeme);
+			}
+			token.lexemes().pop_back();
+		}
+		changed.set_value((remaining.size() > 0) && (remaining.size() < original.size()));
+		token.lexemes() = changed.get_value() ? remaining : original;
+	}
 	return changed;
 }
 
-- 
GitLab