From 2f75423d38a0fdda5b5830fd418e8a6603887bed Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 10 Nov 2015 23:19:54 -0500 Subject: [PATCH] string_search: add `Match::text_before` and `Match::text_after` Signed-off-by: Jean Privat --- lib/core/text/string_search.nit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/core/text/string_search.nit b/lib/core/text/string_search.nit index ffd0999..b143e71 100644 --- a/lib/core/text/string_search.nit +++ b/lib/core/text/string_search.nit @@ -277,6 +277,22 @@ class Match # ~~~ redef fun to_s do return string.substring(from,length) + # The content of `string` before the match + # + # ~~~ + # var m = "hello world".search("lo") + # assert m.text_before == "hel" + # ~~~ + fun text_before: String do return string.substring(0, from) + + # The content of `string` after the match + # + # ~~~ + # var m = "hello world".search("lo") + # assert m.text_after == " world" + # ~~~ + fun text_after: String do return string.substring_from(after) + init do assert positive_length: length >= 0 -- 1.7.9.5