Merge pull request #2506 from BlaXpirit/update-pcre

Update and improve PCRE wrapper
This commit is contained in:
Andreas Rumpf 2015-04-21 08:58:28 +02:00
commit 1b80e2f296
2 changed files with 451 additions and 307 deletions

View file

@ -44,11 +44,11 @@ type
reExtended = 3, ## ignore whitespace and ``#`` comments
reStudy = 4 ## study the expression (may be omitted if the
## expression will be used only once)
RegexDesc = object
h: PPcre
e: ptr TExtra
RegexDesc = object
h: ptr Pcre
e: ptr ExtraData
Regex* = ref RegexDesc ## a compiled regular expression
RegexError* = object of ValueError
@ -63,7 +63,7 @@ proc raiseInvalidRegex(msg: string) {.noinline, noreturn.} =
e.msg = msg
raise e
proc rawCompile(pattern: string, flags: cint): PPcre =
proc rawCompile(pattern: string, flags: cint): ptr Pcre =
var
msg: cstring
offset: cint
@ -87,7 +87,7 @@ proc re*(s: string, flags = {reExtended, reStudy}): Regex =
result.h = rawCompile(s, cast[cint](flags - {reStudy}))
if reStudy in flags:
var msg: cstring
result.e = pcre.study(result.h, 0, msg)
result.e = pcre.study(result.h, 0, addr msg)
if not isNil(msg): raiseInvalidRegex($msg)
proc matchOrFind(s: string, pattern: Regex, matches: var openArray[string],