Added 'openArray[char]' overloads to 'std/parseutils' (#20527)

* Added 'openarray[char]' overloads to 'std/parseutils'

* Removed redundant `start` and `last` params from slice using procs

* Fixed type for parseIdent overload

* fixed one by off with 'substr'

* removed missed start parameters for procedures

* Added 'openarray[char]' overloads to 'std/parseutils'

* Removed redundant `start` and `last` params from slice using procs

* Fixed type for parseIdent overload

* fixed one by off with 'substr'

* removed missed start parameters for procedures

* Fixed VM op to work with new 'opcSlice'

* Corrected captureBetween's logic to work with openarray

* js sys's parsefloat logic now uses openarray

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
This commit is contained in:
Jason Beetham 2022-10-24 12:50:54 -06:00 • committed by GitHub
commit ea0e45e62f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 550 additions and 162 deletions

View file

@ -2580,7 +2580,19 @@ template once*(body: untyped): untyped =
{.pop.} # warning[GcMem]: off, warning[Uninit]: off
proc substr*(s: string, first, last: int): string =
proc substr*(s: openArray[char]): string =
## Copies a slice of `s` into a new string and returns this new
## string.
runnableExamples:
let a = "abcdefgh"
assert a.substr(2, 5) == "cdef"
assert a.substr(2) == "cdefgh"
assert a.substr(5, 99) == "fgh"
result = newString(s.len)
for i, ch in s:
result[i] = ch
proc substr*(s: string, first, last: int): string = # A bug with `magic: Slice` requires this to exist this way
## Copies a slice of `s` into a new string and returns this new
## string.
##