Revert "[std/re]fix terrible and strange interface" (#18027)

This reverts commit c218f2ba0b.
This commit is contained in:
flywind 2021-05-16 11:10:41 +08:00 • committed by GitHub
commit 65f6b66820
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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