fix parseChar see #16240 (#16245)

* fix parseChar

* do not introduce new double backticks
This commit is contained in:
Pietro Peterlongo 2020-12-06 10:14:55 +01:00 • committed by GitHub
commit 57d2c293d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -211,6 +211,7 @@ proc parseHex*[T: SomeInteger](s: string, number: var T, start = 0,
proc parseIdent*(s: string, ident: var string, start = 0): int = proc parseIdent*(s: string, ident: var string, start = 0): int =
## Parses an identifier and stores it in ``ident``. Returns ## Parses an identifier and stores it in ``ident``. Returns
## the number of the parsed characters or 0 in case of an error. ## the number of the parsed characters or 0 in case of an error.
## If error, the value of `ident` is not changed.
runnableExamples: runnableExamples:
var res: string var res: string
doAssert parseIdent("Hello World", res, 0) == 5 doAssert parseIdent("Hello World", res, 0) == 5
@ -241,8 +242,18 @@ proc parseIdent*(s: string, start = 0): string =
while i < s.len and s[i] in IdentChars: inc(i) while i < s.len and s[i] in IdentChars: inc(i)
result = substr(s, start, i-1) result = substr(s, start, i-1)
proc parseChar*(s: string, ident: var char, start = 0): int = proc parseChar*(s: string, c: var char, start = 0): int =
ident = s[start] ## Parses a single character, stores it in `c` and returns 1.
## In case of error (if start >= s.len) it returns 0
## and the value of `c` is unchanged.
runnableExamples:
var c: char
doAssert "nim".parseChar(c, 3) == 0
doAssert c == '\0'
doAssert "nim".parseChar(c, 0) == 1
doAssert c == 'n'
if start < s.len:
c = s[start]
result = 1 result = 1
proc skipWhitespace*(s: string, start = 0): int {.inline.} = proc skipWhitespace*(s: string, start = 0): int {.inline.} =