diff options
author | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-10 18:00:07 -0500 |
---|---|---|
committer | Flaviu Tamas <tamasflaviu@gmail.com> | 2015-01-10 18:00:07 -0500 |
commit | cc33942d893b339f87976008b06bc55b8a36d5f0 (patch) | |
tree | 1480cd41618e52def5991127ade69d0a23d25dde /src/nre.nim | |
parent | f692042bb835642d7d0f3296b3c6b2ea60737ecf (diff) | |
download | Nim-cc33942d893b339f87976008b06bc55b8a36d5f0.tar.gz |
Revert "Remove Option from exec(Regex, string, int)"
This reverts commit f692042bb835642d7d0f3296b3c6b2ea60737ecf.
Diffstat (limited to 'src/nre.nim')
-rw-r--r-- | src/nre.nim | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/nre.nim b/src/nre.nim index 631be2176..5a5cbaa45 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -215,10 +215,7 @@ proc initRegex*(pattern: string, options = "Sx"): Regex = result.captureNameToId = result.getNameToNumberTable() # }}} -proc exec*(self: Regex, str: string, start = 0): RegexMatch = - ## Tries to match the regex on the string `str` starting at `start`. - ## On fail, returns `nil` - ## On success, returns RegexMatch +proc exec*(self: Regex, str: string, start = 0): Option[RegexMatch] = var result: RegexMatch new(result) result.pattern = self @@ -239,8 +236,8 @@ proc exec*(self: Regex, str: string, start = 0): RegexMatch = cint(0), cast[ptr cint](addr result.pcreMatchBounds[0]), cint(vecsize)) if execRet >= 0: - return result + return Some(result) elif execRet == pcre.ERROR_NOMATCH: - return nil + return None[RegexMatch]() else: raise newException(AssertionError, "Internal error: errno " & $execRet) |