encoding/toml
Reading and writing TOML configuration files.
import encoding.toml
On this page
TOML is a straightforward configuration format of [section] tables and key = value pairs. This package turns it into a dynamic Value and back.
Functions
DecodeStrict
func DecodeStrict(text: str, ok &: bool): value.ValueReads TOML, setting
ok false when the text is not valid.import encoding.toml
import encoding.value
func main:
text := "title = \"salam\"\n\n[server]\nhost = \"localhost\"\nport = 8080\ntags = [\"a\", \"b\"]\n"
println toml.Valid(text), toml.Valid("= no key")
v := toml.Decode(text)
server := value.ObjectGet(v, "server")
println value.AsString(value.ObjectGet(v, "title")), value.AsInt(value.ObjectGet(server, "port"))
println toml.Encode(v)
mut read := false
_ := toml.DecodeStrict("a = \n", read)
println read
mut wrote := false
println toml.EncodeStrict(value.ValueInt(1), wrote), wrote
endOutputtrue false
salam 8080
title = "salam"
[server]
host = "localhost"
tags = ["a", "b"]
port = 8080
false
false
Decode
func Decode(text: str): value.ValueTurns TOML into a
Value; when the text is not valid it returns whatever was read before the error.The example for this item is shown with the ones above: encoding-toml-Decode.salam
Valid
func Valid(text: str): boolTrue when the text is valid TOML.
The example for this item is shown with the ones above: encoding-toml-Decode.salam
EncodeStrict
func EncodeStrict(v: value.Value, ok &: bool): strTurns a value into TOML; the top level has to be an object, or
ok turns false.The example for this item is shown with the ones above: encoding-toml-Decode.salam
Encode
func Encode(v: value.Value): strTurns a value into TOML.
The example for this item is shown with the ones above: encoding-toml-Decode.salam