diff options
author | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-10 19:23:15 -0500 |
---|---|---|
committer | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-10 19:23:15 -0500 |
commit | d7dbf7e01177c67e8438aff814aa9263312d87b1 (patch) | |
tree | d828cf789db4694e3e274d43b1f433a503f01071 /src | |
parent | 4f4a7dfa5b00e39114b6779f84e6dc2fd21723c4 (diff) | |
download | Nim-d7dbf7e01177c67e8438aff814aa9263312d87b1.tar.gz |
Rename exec(...) and extend it
Diffstat (limited to 'src')
-rw-r--r-- | src/nre.nim | 8 |
1 files changed, 6 insertions, 2 deletions
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)) |