summary refs log tree commit diff stats
path: root/changelog.md
diff options
context:
space:
mode:
authorc-blake <c-blake@users.noreply.github.com>2023-02-14 02:00:30 -0500
committerGitHub <noreply@github.com>2023-02-14 08:00:30 +0100
commit1d06c2b6cf84bcf65b67e88667dba4fd5e8ba519 (patch)
tree8c65f7f9cc880db4856d5030e1c13e34161a9a89 /changelog.md
parent406d3021314c66fdf4c715efeeaea3c8f478fcaa (diff)
downloadNim-1d06c2b6cf84bcf65b67e88667dba4fd5e8ba519.tar.gz
This adds `parseutils.parseSize`, an inverse to `strutils.formatSize` (#21349)
* This adds `parseutils.parseSize`, an inverse to `strutils.formatSize`
which has existed since 2017.

It is useful for parsing the compiler's own output logs (like SuccessX)
or many other scenarios where "human readable" units have been chosen.
The doc comment and tests explain accepted syntax in detail.

Big units lead to small numbers, often with a fractional part, but we
parse into an `int64` since that is what `formatSize` stringifies and
this is an inverse over partial function slots.  Although metric
prefixes z & y for zettabyte & yottabyte are accepted, these will
saturate the result at `int64.high` unless the qualified number is a
small fraction.  This should not be much of a problem until such sizes
are common (at which point another overload with the parse result
either `float64` or `int128` could be added).

Tests avoids `test()` because of a weakly related static: test() failure
as mentioned in https://github.com/nim-lang/Nim/pull/21325. This is a
more elemental VM failure.  As such, it needs its own failure exhibition
issue that is a smaller test case.  (I am working on that, but unless
there is a burning need to `parseSize` at compile-time before run-time
it need not hold up this PR.)

* This worked with `int` but fails with `int64`.  Try for green tests.

* Lift 2-result matching into a `checkParseSize` template and format as a
table of input & 2 expected outputs which seems nicer and to address
https://github.com/nim-lang/Nim/pull/21349#pullrequestreview-1294407679

* Fix (probably) the i386 trouble by using `int64` consistently.

* Improve documentation by mentioning saturation.

* Improve documentation with `runnableExamples` and a little more detail in
the main doc comment based on excellent code review by @juancarlospaco:
https://github.com/nim-lang/Nim/pull/21349#pullrequestreview-1294564155

* Address some more @juancarlospaco code review concerns.

* Remove a stray space.

* Mention milli-bytes in docs to maybe help clarify why wild conventions
are so prone to going case-insensitive-metric.

* Add some parens.
Diffstat (limited to 'changelog.md')
-rw-r--r--changelog.md2
1 files changed, 1 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 0389faad9..2db577d0b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -10,7 +10,7 @@
 
 
 [//]: # "Additions:"
-
+- Added `parseutils.parseSize` - inverse to `strutils.formatSize` - to parse human readable sizes.
 
 [//]: # "Deprecations:"