[std/re]fix terrible and strange interface

This commit is contained in:
flywind
2021-05-16 10:39:52 +08:00
committed by GitHub
parent 3614523664
commit c218f2ba0b

View File

@@ -142,7 +142,7 @@ proc matchOrFind(buf: cstring, pattern: Regex, matches: var openArray[string],
return rawMatches[1] - rawMatches[0]
proc findBounds*(buf: cstring, pattern: Regex, matches: var openArray[string],
start = 0, bufSize: int): tuple[first, last: int] =
start = 0, bufSize = 0): tuple[first, last: int] =
## returns the starting position and end position of `pattern` in `buf`
## (where `buf` has length `bufSize` and is not necessarily `'\0'` terminated),
## and the captured
@@ -200,7 +200,7 @@ proc findBounds*(s: string, pattern: Regex,
result = findBounds(cstring(s), pattern, matches, start, s.len)
proc findBounds*(buf: cstring, pattern: Regex,
start = 0, bufSize: int): tuple[first, last: int] =
start = 0, bufSize = 0): tuple[first, last: int] =
## returns the `first` and `last` position of `pattern` in `buf`,
## where `buf` has length `bufSize` (not necessarily `'\0'` terminated).
## If it does not match, `(-1,0)` is returned.
@@ -239,7 +239,7 @@ proc matchLen*(s: string, pattern: Regex, matches: var openArray[string],
result = matchOrFind(cstring(s), pattern, matches, start.cint, s.len.cint, pcre.ANCHORED)
proc matchLen*(buf: cstring, pattern: Regex, matches: var openArray[string],
start = 0, bufSize: int): int {.inline.} =
start = 0, bufSize = 0): int {.inline.} =
## the same as `match`, but it returns the length of the match,
## if there is no match, `-1` is returned. Note that a match length
## of zero can happen.
@@ -281,7 +281,7 @@ proc match*(s: string, pattern: Regex, matches: var openArray[string],
result = matchLen(cstring(s), pattern, matches, start, s.len) != -1
proc match*(buf: cstring, pattern: Regex, matches: var openArray[string],
start = 0, bufSize: int): bool {.inline.} =
start = 0, bufSize = 0): bool {.inline.} =
## returns `true` if `buf[start..<bufSize]` matches the `pattern` and
## the captured substrings in the array `matches`. If it does not
## match, nothing is written into `matches` and `false` is
@@ -315,7 +315,7 @@ proc find*(s: string, pattern: Regex, matches: var openArray[string],
## is written into `matches` and `-1` is returned.
result = find(cstring(s), pattern, matches, start, s.len)
proc find*(buf: cstring, pattern: Regex, start = 0, bufSize: int): int =
proc find*(buf: cstring, pattern: Regex, start = 0, bufSize = 0): int =
## returns the starting position of `pattern` in `buf`,
## where `buf` has length `bufSize` (not necessarily `'\0'` terminated).
## If it does not match, `-1` is returned.
@@ -359,7 +359,7 @@ iterator findAll*(s: string, pattern: Regex, start = 0): string =
yield substr(s, int(a), int(b)-1)
i = b
iterator findAll*(buf: cstring, pattern: Regex, start = 0, bufSize: int): string =
iterator findAll*(buf: cstring, pattern: Regex, start = 0, bufSize = 0): string =
## Yields all matching `substrings` of `s` that match `pattern`.
##
## Note that since this is an iterator you should not modify the string you