Documentation
¶
Index ¶
- Constants
- Variables
- func Advance(s string, t StringToken) bool
- func AsArguments(s string) []string
- func Extract(src []string, rules ...interface{}) ([]string, error)
- func ExtractSep(path, separator string, rules ...interface{}) ([]string, error)
- func FindTreeInt(path string, root interface{}) (int, bool)
- func FindTreeString(path string, root interface{}) (string, bool)
- func FindTreeValue(_path string, _tree interface{}) (interface{}, bool)
- func Path(_path string, opts PathOpts, rules ...interface{}) ([]string, error)
- func PathOne(path string, opts PathOpts, rules ...interface{}) string
- func PathTwo(path string, opts PathOpts, rules ...interface{}) (string, string)
- func ReadJsonFile(filename string) (interface{}, error)
- func ReplacePairs(s string, pairs ...interface{}) string
- func SetTreeInt(path string, value int, tree interface{}) (interface{}, error)
- func SetTreeString(path, value string, tree interface{}) (interface{}, error)
- func SolveInt(s string) (int, error)
- func TreeBool(path string, root interface{}, defaultValue bool) bool
- func TreeInt(path string, root interface{}, defaultValue int) int
- func TreeString(path string, root interface{}, defaultValue string) string
- func TreeStringSlice(path string, root interface{}) []string
- func TreeValue(path string, tree interface{}) (interface{}, error)
- type KeepAllRuleT
- type KeepRuleT
- type PathOpts
- type ReplaceRuleT
- type SkipRuleT
- type StringMatch
- type StringToken
Constants ¶
const (
TreeSeparator = "/"
)
Variables ¶
var ( KeepRule = KeepRuleT{} KeepAllRule = KeepAllRuleT{} SkipRule = SkipRuleT{} )
Functions ¶
func Advance ¶
func Advance(s string, t StringToken) bool
func Advance() advances the token until it finds the string, returning true if it's found. The token will be left on the next string.
func AsArguments ¶
AsArguments() parses a single string into a slice based on typical command line argument rules (spaces separate tokens, except when quoted, and in that case quotes are removed). Note: seems very likely there's already something to handle this in go, but I'm not seeing it.
func Extract ¶
func Extract() takes a list of strings and returns portions of it, according to the rules. Rules can contain either strings or an ExtractRule. Strings:
The node must match the string exactly. It is not included in the response.
ExtractRules:
KeepRule. Node can be anything. It is returned in the response. SkipRule. Node can be anything. It is not included in the response.
func ExtractSep ¶
func ExtractSep() is a wrapper on Extract(), first splitting the string based on the separator.
func FindTreeInt ¶
FindTreeInt() finds the value at the given path and answers it as an int, if it's convertible.
func FindTreeString ¶
FindTreeString() func follows a path down an arbitrary object to answer a string at the root. The path is "/" separated to enter maps. Note: This is identical to TreeString(), but I'm acknowledging, for all the convenience of that API in certain situations, I should have stuck to a more go-way of doing things.
func FindTreeValue ¶
func Path ¶
func Path() takes a list of strings and returns portions of it, according to the rules. Rules can contain either strings or a path rule. Strings:
The node must match the string exactly. It is not included in the response.
Path rules:
KeepRule. Node can be anything. It is returned in the response. KeepAllRule. All remaining nodes are added to the response and returned. ReplaceRuleT. Replace this item with the Replace.With. SkipRule. Node can be anything. It is not included in the response.
func PathOne ¶
PathOne() answers a single item from the path input, reconstructed from the results. There's no error reporting, if you need more complete information use a more complex form.
func PathTwo ¶
PathTwo() answers two items from the path input. There's no error reporting, if you need more complete information use a more complex form.
func ReadJsonFile ¶
func ReplacePairs ¶
ReplacePairs() takes a string and applies a series of replace pairs. For each pair in the arguments, the first value is found and replaced with the second. The second argument can be anything that can reduce down to a string, including a function with no arguments that returns a string.
func SetTreeInt ¶
func SetTreeString ¶
func TreeString ¶
func TreeStringSlice ¶
Types ¶
type KeepAllRuleT ¶
type KeepAllRuleT struct{}
type ReplaceRuleT ¶
type ReplaceRuleT struct {
With string
}
type StringMatch ¶
interface StringMatch describes an object that can match strings.
func NewMqttStringMatch ¶
func NewMqttStringMatch(_pattern string) StringMatch
type StringToken ¶
type StringToken interface { Empty() bool Next() (string, error) // Answer the remaining items. This leaves the token empty. Remainder() ([]string, error) }
interface StringToken allows iterating over a series of strings.
func NewStringToken ¶
func NewStringToken(tokens ...string) StringToken
Answer a new iterating string token from a list of strings.