Add isInteger and isString procs for testing against values

This commit is contained in:
Emery Hemingway 2023-05-30 13:11:03 +01:00
parent c500e99b95
commit 0f697349cc
2 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "20230520"
version = "20230530"
author = "Emery Hemingway"
description = "data model and serialization format"
license = "Unlicense"

View File

@ -396,11 +396,19 @@ func isDouble*(pr: Preserve): bool {.inline.} = pr.kind == pkDouble
## Check if ``pr`` is a Preserve double.
func isInteger*(pr: Preserve): bool {.inline.} = pr.kind == pkSignedInteger
## Check if ``pr`` is a Preserve double.
## Check if ``pr`` is a Preserve integer.
func isInteger*(pr: Preserve; i: SomeInteger): bool {.inline.} =
## Check if ``pr`` is a Preserve integer equivalent to `i`.
pr.kind == pkSignedInteger and pr.int == BiggestInt(i)
func isString*(pr: Preserve): bool {.inline.} = pr.kind == pkString
## Check if ``pr`` is a Preserve text string.
func isString*(pr: Preserve; s: string): bool {.inline.} =
## Check if ``pr`` is a Preserve text string equivalent to `s`.
pr.kind == pkString and pr.string == s
func isByteString*(pr: Preserve): bool {.inline.} = pr.kind == pkByteString
## Check if ``pr`` is a Preserves byte string.