Skip to content

Commit

Permalink
string_search: add Match::text_before and Match::text_after
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <jean@pryen.org>
  • Loading branch information
privat committed Nov 11, 2015
1 parent 02376af commit 2f75423
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/core/text/string_search.nit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f75423

Please sign in to comment.