Capy-Bearer Documentation

join_kv

lib call

Capy

function join_kv(value : dval, opt : dval = {}) string

Description

join_kv() encodes a map for split_kv().

opt.separator separates each key from its value. The default is =. An empty value emits no key and value separator.

opt.pair_separator separates pairs. The default is ,. An empty value emits no pair separator.

opt.escape_chars lists valid escape characters. The default is \. The encoder uses the first character as its escape character. An empty value disables escaping.

The function escapes separators, pair separators, and escape characters in keys and values. Use the same options with split_kv() to recover the map. A disabled separator can make a multi-entry format ambiguous. Enable all separators when the output must round-trip.

Parameters

value : map-shaped dval to encode

opt : encoder options

Return Values

A string that contains escaped key and value pairs.

Errors

The function traps when an option has an unknown name or the wrong type.

Example

Capy

var encoded := join_kv({"na=me": "Ada, Lovelace", "role": "admin"})
var decoded := split_kv(encoded)
print(decoded["na=me"], " ", decoded.role, "\n")

Example

Capy

var options := {separator: "::", pair_separator: "||"}
var encoded := join_kv({name: "Ada", note: "one||two"}, options)
print(split_kv(encoded, options).note, "\n")