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
|
|
@ -725,15 +725,20 @@ const
|
|||
IdentChars = {'a'..'z', 'A'..'Z', '0'..'9', '_'}
|
||||
|
||||
|
||||
proc parseFloatNative(a: string): float =
|
||||
let a2 = a.cstring
|
||||
proc parseFloatNative(a: openarray[char]): float =
|
||||
var str = ""
|
||||
for x in a:
|
||||
str.add x
|
||||
|
||||
let cstr = cstring str
|
||||
|
||||
asm """
|
||||
`result` = Number(`a2`);
|
||||
`result` = Number(`cstr`);
|
||||
"""
|
||||
|
||||
proc nimParseBiggestFloat(s: string, number: var BiggestFloat, start: int): int {.compilerproc.} =
|
||||
proc nimParseBiggestFloat(s: openarray[char], number: var BiggestFloat): int {.compilerproc.} =
|
||||
var sign: bool
|
||||
var i = start
|
||||
var i = 0
|
||||
if s[i] == '+': inc(i)
|
||||
elif s[i] == '-':
|
||||
sign = true
|
||||
|
|
@ -743,14 +748,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, start: int): int
|
|||
if s[i+2] == 'N' or s[i+2] == 'n':
|
||||
if s[i+3] notin IdentChars:
|
||||
number = NaN
|
||||
return i+3 - start
|
||||
return i+3
|
||||
return 0
|
||||
if s[i] == 'I' or s[i] == 'i':
|
||||
if s[i+1] == 'N' or s[i+1] == 'n':
|
||||
if s[i+2] == 'F' or s[i+2] == 'f':
|
||||
if s[i+3] notin IdentChars:
|
||||
number = if sign: -Inf else: Inf
|
||||
return i+3 - start
|
||||
return i+3
|
||||
return 0
|
||||
|
||||
var buf: string
|
||||
|
|
@ -782,7 +787,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, start: int): int
|
|||
addInc()
|
||||
eatUnderscores()
|
||||
number = parseFloatNative(buf)
|
||||
result = i - start
|
||||
result = i
|
||||
|
||||
# Workaround for IE, IE up to version 11 lacks 'Math.trunc'. We produce
|
||||
# 'Math.trunc' for Nim's ``div`` and ``mod`` operators:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue