From d0a52fb3101c23602f63cd8e68f9e509c49d87a4 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Wed, 9 Mar 2011 10:00:45 +0100
Subject: [PATCH] MatchVector first_token and last_token

---
 libwccl/values/matchvector.cpp | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/libwccl/values/matchvector.cpp b/libwccl/values/matchvector.cpp
index a0f1b3b..668267d 100644
--- a/libwccl/values/matchvector.cpp
+++ b/libwccl/values/matchvector.cpp
@@ -29,16 +29,34 @@ std::string MatchVector::var_repr(const std::string &var_name)
 
 Position MatchVector::first_token() const
 {
-	Position p;
-	// TODO
-	return p;
+	if (matches_.empty()) {
+		return Position(Position::Nowhere);
+	} else {
+		Position p = matches_.front()->first_token();
+		for (size_t i = 1; i < matches_.end(); ++i) {
+			Position c = matches_[i]->first_token();
+			if (c.get_value() < p.get_value()) {
+				p = c;
+			}
+		}
+		return p;
+	}
 }
 
 Position MatchVector::last_token() const
 {
-	Position p;
-	// TODO
-	return p;
+	if (matches_.empty()) {
+		return Position(Position::Nowhere);
+	} else {
+		Position p = matches_.front()->last_token();
+		for (size_t i = 1; i < matches_.end(); ++i) {
+			Position c = matches_[i]->last_token();
+			if (c.get_value() > p.get_value()) {
+				p = c;
+			}
+		}
+		return p;
+	}
 }
 
 bool MatchVector::empty() const
-- 
GitLab