diff options
author | lit <litlighilit@foxmail.com> | 2024-06-12 10:13:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 10:13:38 +0800 |
commit | 3915fdc372f99a5c67bee0259635f4655e2fc6dc (patch) | |
tree | 865ce00bf8a7630132c3f4db1368ee8960b7e587 /lib/pure | |
parent | 262ff648aad7cc2062eb94cb6bf3357f9910c448 (diff) | |
download | Nim-3915fdc372f99a5c67bee0259635f4655e2fc6dc.tar.gz |
fixes #23513, parseutils.nim: parseInt's doc example. (#23561)
fixes #23513 Also, the old `runnableExample` is just a copy of `proc parseInt(openArray[char], var int, int)` variant (in Line 1000). --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/parseutils.nim | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim index ce642fcf7..2ca255fa0 100644 --- a/lib/pure/parseutils.nim +++ b/lib/pure/parseutils.nim @@ -460,6 +460,8 @@ proc parseBiggestInt*(s: openArray[char], number: var BiggestInt): int {. var res: BiggestInt doAssert parseBiggestInt("9223372036854775807", res) == 19 doAssert res == 9223372036854775807 + doAssert parseBiggestInt("-2024_05_09", res) == 11 + doAssert res == -20240509 var res = BiggestInt(0) # use 'res' for exception safety (don't write to 'number' in case of an # overflow exception): @@ -474,10 +476,8 @@ proc parseInt*(s: openArray[char], number: var int): int {. ## `ValueError` is raised if the parsed integer is out of the valid range. runnableExamples: var res: int - doAssert parseInt("2019", res, 0) == 4 - doAssert res == 2019 - doAssert parseInt("2019", res, 2) == 2 - doAssert res == 19 + doAssert parseInt("-2024_05_02", res) == 11 + doAssert res == -20240502 var res = BiggestInt(0) result = parseBiggestInt(s, res) when sizeof(int) <= 4: @@ -992,6 +992,10 @@ proc parseBiggestInt*(s: string, number: var BiggestInt, start = 0): int {.noSid var res: BiggestInt doAssert parseBiggestInt("9223372036854775807", res, 0) == 19 doAssert res == 9223372036854775807 + doAssert parseBiggestInt("-2024_05_09", res) == 11 + doAssert res == -20240509 + doAssert parseBiggestInt("-2024_05_02", res, 7) == 4 + doAssert res == 502 parseBiggestInt(s.toOpenArray(start, s.high), number) proc parseInt*(s: string, number: var int, start = 0): int {.noSideEffect, raises: [ValueError].} = @@ -1000,10 +1004,10 @@ proc parseInt*(s: string, number: var int, start = 0): int {.noSideEffect, raise ## `ValueError` is raised if the parsed integer is out of the valid range. runnableExamples: var res: int - doAssert parseInt("2019", res, 0) == 4 - doAssert res == 2019 - doAssert parseInt("2019", res, 2) == 2 - doAssert res == 19 + doAssert parseInt("-2024_05_02", res) == 11 + doAssert res == -20240502 + doAssert parseInt("-2024_05_02", res, 7) == 4 + doAssert res == 502 parseInt(s.toOpenArray(start, s.high), number) |