From 9d85b6004263ff1a0de3abdd20ff4517d8d756b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 30 Aug 2015 09:52:20 -0400 Subject: [PATCH] lib/re: fix offset of submatches and clarify variables name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/core/re.nit | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/core/re.nit b/lib/core/re.nit index ecf9469..33ab76c 100644 --- a/lib/core/re.nit +++ b/lib/core/re.nit @@ -355,6 +355,7 @@ class Regex # assert "el+o".to_re.search_in("hello world", 0).from == 1 # assert "l+".to_re.search_in("hello world", 3).from == 3 # assert "z".to_re.search_in("hello world", 0) == null + # assert "cd(e)".to_re.search_in("abcdef", 2)[1].to_s == "e" redef fun search_in(text, from) do assert not optimize_has @@ -378,19 +379,19 @@ class Regex # Found one? if res == 0 then - var bso = bstr.byte_to_char_index(native_match.rm_so) - var ln = bstr.byte_to_char_index(native_match.rm_eo - native_match.rm_so - 1) + var first_char = bstr.byte_to_char_index(native_match.rm_so) + var last_char = bstr.byte_to_char_index(native_match.rm_eo - native_match.rm_so - 1) var match = new Match(text, - from + bso, - ln + 1) + from + first_char, + last_char + 1) # Add sub expressions for i in [1 .. nsub] do - bso = bstr.byte_to_char_index(native_match[i].rm_so) - ln = bstr.byte_to_char_index(native_match[i].rm_eo - native_match[i].rm_so - 1) + first_char = bstr.byte_to_char_index(native_match[i].rm_so) + last_char = bstr.byte_to_char_index(native_match[i].rm_eo - native_match[i].rm_so - 1) match.subs.add new Match( text, - bso , - ln + 1) + from + first_char, + last_char + 1) end return match -- 1.7.9.5