jsonutils: add customization for toJson via ToJsonOptions; generalize symbolName; add symbolRank (#18029)

* jsonutils: add customization for toJson via `ToJsonOptions`

* add enumutils.symbolRank

* lookup table implementation for HoleyEnum

* cleanup

* changelog

* fixup

* Update lib/std/jsonutils.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Timothee Cour 2021-05-18 06:10:19 -07:00 • committed by GitHub
commit 7f077a76fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 14 deletions

View file

@ -118,9 +118,11 @@
- `json.%`,`json.to`, `jsonutils.formJson`,`jsonutils.toJson` now work with `uint|uint64`
instead of raising (as in 1.4) or giving wrong results (as in 1.2).
- `jsonutils` now handles `cstring` (including as Table key), and `set`.
- added `jsonutils.jsonTo` overload with `opt = Joptions()` param.
- `jsonutils` now handles `cstring` (including as Table key), and `set`.
- `jsonutils.toJson` now supports customization via `ToJsonOptions`.
- Added an overload for the `collect` macro that inferes the container type based
on the syntax of the last expression. Works with std seqs, tables and sets.
@ -138,6 +140,7 @@
- Added `std/enumutils` module. Added `genEnumCaseStmt` macro that generates case statement to parse string to enum.
Added `items` for enums with holes.
Added `symbolName` to return the enum symbol name ignoring the human readable name.
Added `symbolRank` to return the index in which an enum member is listed in an enum.
- Added `typetraits.HoleyEnum` for enums with holes, `OrdinalEnum` for enums without holes.