From d7dbf7e01177c67e8438aff814aa9263312d87b1 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sat, 10 Jan 2015 19:23:15 -0500 Subject: Rename exec(...) and extend it --- src/nre.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nre.nim b/src/nre.nim index 76532efee..b6835bd00 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -253,7 +253,11 @@ proc initRegex*(pattern: string, options = "Sx"): Regex = result.captureNameToId = result.getNameToNumberTable() # }}} -proc exec*(self: Regex, str: string, start = 0): Option[RegexMatch] = +proc match*(self: Regex, str: string, start = 0, endpos = -1): Option[RegexMatch] = + ## Returns Some if there is a match between `start` and `endpos`, otherwise + ## it returns None. + ## + ## if `endpos == -1`, then `endpos = str.len` var result: RegexMatch new(result) result.pattern = self @@ -269,7 +273,7 @@ proc exec*(self: Regex, str: string, start = 0): Option[RegexMatch] = let execRet = pcre.exec(self.pcreObj, self.pcreExtra, cstring(str), - cint(str.len), + cint(max(str.len, endpos)), cint(start), cint(0), cast[ptr cint](addr result.pcreMatchBounds[0]), cint(vecsize)) -- cgit 1.4.1-2-gfad0