chiark / gitweb /
TOML::Tiny: Try to be more faithful for small decimals
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 4 May 2020 00:19:49 +0000 (01:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 5 May 2020 20:10:56 +0000 (21:10 +0100)
commit0f492f56ab1195f078e6c82dda4b55edccf2f66a
tree15d7e80d71037cc56ac4be741bb1158545a38d5b
parentdbb0699fd1e23c2eb747935973f278b83229959d
TOML::Tiny: Try to be more faithful for small decimals

Ideally, if we read a TOML file and write it back out again, we get a
semantically equivalent TOML file.  Here we improve the situation
for smallish deciaml integers.

We check for values that round trip from string through a perl integer
and back to the same string; if they do, return that integer rather
than the string.

The main point of this check is to avoid losing information if the
value is too large to fit into a Perl integer, which might be only
32-bit.

This technique is not perfect: it can't cope with hex, octal or
binary, or with larger values that would need bignums.  But it is an
improvement and probably the best that can be done without
unreasonable effort.
README.pod
lib/TOML/Tiny.pm
lib/TOML/Tiny/Tokenizer.pm