ported re.nim to ARC
This commit is contained in:
parent
8f17a70fe1
commit
bafb4f119c
1 changed files with 10 additions and 1 deletions
|
|
@ -45,6 +45,12 @@ type
|
||||||
RegexError* = object of ValueError
|
RegexError* = object of ValueError
|
||||||
## is raised if the pattern is no valid regular expression.
|
## is raised if the pattern is no valid regular expression.
|
||||||
|
|
||||||
|
when defined(gcDestructors):
|
||||||
|
proc `=destroy`(x: var RegexDesc) =
|
||||||
|
pcre.free_substring(cast[cstring](x.h))
|
||||||
|
if not isNil(x.e):
|
||||||
|
pcre.free_study(x.e)
|
||||||
|
|
||||||
proc raiseInvalidRegex(msg: string) {.noinline, noreturn.} =
|
proc raiseInvalidRegex(msg: string) {.noinline, noreturn.} =
|
||||||
var e: ref RegexError
|
var e: ref RegexError
|
||||||
new(e)
|
new(e)
|
||||||
|
|
@ -73,6 +79,9 @@ proc re*(s: string, flags = {reStudy}): Regex =
|
||||||
## Note that Nim's
|
## Note that Nim's
|
||||||
## extended raw string literals support the syntax ``re"[abc]"`` as
|
## extended raw string literals support the syntax ``re"[abc]"`` as
|
||||||
## a short form for ``re(r"[abc]")``.
|
## a short form for ``re(r"[abc]")``.
|
||||||
|
when defined(gcDestructors):
|
||||||
|
result = Regex()
|
||||||
|
else:
|
||||||
new(result, finalizeRegEx)
|
new(result, finalizeRegEx)
|
||||||
result.h = rawCompile(s, cast[cint](flags - {reStudy}))
|
result.h = rawCompile(s, cast[cint](flags - {reStudy}))
|
||||||
if reStudy in flags:
|
if reStudy in flags:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue