Patch #185 introduced a backward incompatibility by changing the arguments
of the `Set*` methods on `Tree`.
This change restores the arguments to what they previous were, and
introduces `SetWithComment` and `SetPathWithComment` to perform the same
action.
This fixes two unmarshalling issues:
1. Unmarshalling into a custom integer/float type (e.g. `time.Duration`).
2. Checks for overflows happen before unmarshalling, erroring if an overflow
would happen.
Apart from this it also reduces code duplication a bit.
Patch #193 introduced a regression in the toml-tests examples, but it was
never caught because test.sh was exiting with a zero status code, even
though the tests failed. This is because of the `|tee` operation when
invoking toml-test, without setting the pipefail option, reporting the
status code of `tee` instead of `toml-test`.
Add support for non-decimal integers. At the time of writing, this is an
unreleased backward-compatible feature of TOML:
```
Non-negative integer values may also be expressed in hexadecimal, octal, or
binary. In these formats, leading zeros are allowed (after the prefix). Hex
values are case insensitive. Underscores are allowed between digits (but
not between the prefix and the value).
# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755 # useful for Unix file permissions
# binary with prefix `0b`
bin1 = 0b11010110
```
Fixes#204
A new Encoder option emits arrays with more than one line on multiple lines.
This is off by default and toggled with `ArraysWithOneElementPerLine`.
For example:
```
A = [1,2,3]
```
Becomes:
```
A = [
1,
2,
3
]
```
Fixes#200
Usage is similar to the stdlibs JSON encoder/decoder but I tried to
leave the general structure of the code the same.
Main motivation was to support encoding/decoding options to allow
encoding string-type map keys as quoted TOML keys.
This was implemented on the Encoder with QuoteMapKeys(bool).
> The TOML spec supports using UTF-8 strings as keys.
> https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md#table
* Don't use fmt.Sprintf on simple strings
* Use bytes.Buffer in encodeTomlString
name old time/op new time/op delta
Lexer-8 162µs ± 0% 161µs ± 0% -0.12%
TreeToTomlString-8 19.7µs ± 0% 7.5µs ± 0% -61.80%
name old alloc/op new alloc/op delta
TreeToTomlString-8 9.75kB ± 0% 4.96kB ± 0% -49.12%
name old allocs/op new allocs/op delta
TreeToTomlString-8 485 ± 0% 78 ± 0% -83.92%
Move all the query system to its own package. The reason is to
avoid it to rely on unexported methods and structures, and move
it out of the main package since this is really not a core
feature. It is still tied to the toml.TomlTree and toml.Position
structures for now.
* Move query mechanism to its own subpackage
* Rename QueryResult to Result to avoid stutter
* Add query.CompileAndExecute
Fixes#116
Previously we'd create an empty array and need to continuously resize
it as we appended more entries. This way we immediately create the
correct size array, and then add entries to it.
* Make TreeFromMap reflect to construct tree
* Fix wording of invalid value type in writeTo
Fixes#138, #139, #134⚠️ TreeFromMap signature changed to `TreeFromMap(map[string]interface{}) (*TomlTree, error)`