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:
parent
eed1b6df20
commit
ea0e45e62f
8 changed files with 550 additions and 162 deletions
|
|
@ -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.
|
||||
##
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue