Revert "Remove Option from exec(Regex, string, int)"
This reverts commit f692042bb8.
This commit is contained in:
parent
f692042bb8
commit
cc33942d89
1 changed files with 3 additions and 6 deletions
|
|
@ -215,10 +215,7 @@ proc initRegex*(pattern: string, options = "Sx"): Regex =
|
||||||
result.captureNameToId = result.getNameToNumberTable()
|
result.captureNameToId = result.getNameToNumberTable()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
proc exec*(self: Regex, str: string, start = 0): RegexMatch =
|
proc exec*(self: Regex, str: string, start = 0): Option[RegexMatch] =
|
||||||
## Tries to match the regex on the string `str` starting at `start`.
|
|
||||||
## On fail, returns `nil`
|
|
||||||
## On success, returns RegexMatch
|
|
||||||
var result: RegexMatch
|
var result: RegexMatch
|
||||||
new(result)
|
new(result)
|
||||||
result.pattern = self
|
result.pattern = self
|
||||||
|
|
@ -239,8 +236,8 @@ proc exec*(self: Regex, str: string, start = 0): RegexMatch =
|
||||||
cint(0),
|
cint(0),
|
||||||
cast[ptr cint](addr result.pcreMatchBounds[0]), cint(vecsize))
|
cast[ptr cint](addr result.pcreMatchBounds[0]), cint(vecsize))
|
||||||
if execRet >= 0:
|
if execRet >= 0:
|
||||||
return result
|
return Some(result)
|
||||||
elif execRet == pcre.ERROR_NOMATCH:
|
elif execRet == pcre.ERROR_NOMATCH:
|
||||||
return nil
|
return None[RegexMatch]()
|
||||||
else:
|
else:
|
||||||
raise newException(AssertionError, "Internal error: errno " & $execRet)
|
raise newException(AssertionError, "Internal error: errno " & $execRet)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue