Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCantQuoteString = errors.New("can't quote string")
ErrCantQuoteString is the error Quoted returns if a key or a value contains both a ' and a " which is an un-parseable option.
Functions ¶
func Check ¶
func Check(s string) []listener.Diagnostic
Check parses an option string returning Diagnostics
Types ¶
type Option ¶
Option is the result of Parse-ing an option string. An option string is of the form: `abc: value; y :value0 value1 ; ' z ' : '1st value for z' " 2nd value for z " 3rd; hidden;` i.e. a list of key:value value ...; or key; fragments, where key and value can be anything except "; : tab space cr lf" or anything quoted with single (') or double (") quoutes. If a key appears without a value in the list, it's single value is assumed to be "true". Whitespace is trimmed in the first form but not in the quoted form. There are no quotes of the same form allowed in the quoted form and there is no escaping. In the example above abc is [value], y is [value0 value1], " z " is the list of this three strings: "1st value for z" " 2nd value for z " "3rd", note the trimmed and not trimmed key/values. hidden is [true], so IsSet("hidden") returns true.
func Parse ¶
Parse parses a new Option map. Please note that "last occurrance wins", i.e. if a key is given more than once in s, the value list of the last occurrance is considered to be *the* value of the key. E.g. "a: a; a: 1 2 3;" returns an Option with a=[1 2 3]
func (Option) GetValue ¶
GetValue looks up a particular option value. If doesn't exist or it has length zero an empty string is returned. If it has length one, the first element is returned. If it has length two or more, the slice is Sprint-ed and returned. If you need the splice, just use standard map lookup.
func (Option) IsGiven ¶ added in v0.6.12
IsGiven returns true if the key is present in the parsed map. The method exists to prevent a possible misinterpretation of IsSet() which checks if an option is truthy.
func (Option) IsSet ¶
IsSet returns true if the list at k is exactly one element long and this single value is one of [true 1 on set yes]
func (Option) Quoted ¶ added in v0.6.12
Quoted returns a normalized parseable string represention of the Option. Boolean true flags, see IsSet, reproduce their original string value and "true" in case it was left out. It returns ErrCantQuoteString and the offending key/value, if the Option contains a key or a value that both contains a single and a double quote, which is not allowed by the parser but can be constructed via the standard map functionality of Option.
func (Option) String ¶
String returns a human readable representation of options, not their raw input. If you need a re-parseable string use Quoted. Keys are sorted as strings and listed in order. Lists are represented by unquoted, comma-separated strings. Especially boolean true values, see IsSet(), are shown in their key-only form.