Documentation ¶
Overview ¶
Package strutil collects utils supplemental to the standard strings package.
Index ¶
- func Base32ExtDecode(text []byte) (data []byte, err error)
- func Base32ExtEncode(data []byte) (text []byte)
- func Base64Decode(text []byte) (data []byte, err error)
- func Base64Encode(data []byte) (text []byte)
- func JoinFields(flds []string, sep string) string
- func PrettyPrint(w io.Writer, v interface{}, prefix, suffix string, hooks PrettyPrintHooks)
- func PrettyString(v interface{}, prefix, suffix string, hooks PrettyPrintHooks) string
- func SplitFields(s, sep string) (flds []string)
- func StrPack(s string) string
- type Dict
- type Formatter
- type GoDict
- type GoPool
- type Pool
- type PrettyPrintHooks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base32ExtDecode ¶
Base32ExtDecode decodes base32 extended (RFC 4648) text to binary data.
func Base32ExtEncode ¶
Base32ExtEncode encodes binary data to base32 extended (RFC 4648) encoded text.
func Base64Decode ¶
Base64Decode decodes base64 text to binary data.
func Base64Encode ¶
Base64Encode encodes binary data to base64 encoded text.
func JoinFields ¶
JoinFields returns strings in flds joined by sep. Flds may contain arbitrary bytes, including the sep as they are safely escaped. JoinFields panics if sep is the backslash character or if len(sep) != 1.
func PrettyPrint ¶
func PrettyPrint(w io.Writer, v interface{}, prefix, suffix string, hooks PrettyPrintHooks)
PrettyPrint pretty prints v to w. Zero values and unexported struct fields are omitted.
func PrettyString ¶
func PrettyString(v interface{}, prefix, suffix string, hooks PrettyPrintHooks) string
PrettyString returns the output of PrettyPrint as a string.
func SplitFields ¶
SplitFields splits s, which must be produced by JoinFields using the same sep, into flds. SplitFields panics if sep is the backslash character or if len(sep) != 1.
Types ¶
type Dict ¶
type Dict struct {
// contains filtered or unexported fields
}
Dict is a string <-> id bijection. Dict is *not* concurrent access safe for assigning new ids to strings not yet contained in the bijection. Id for an empty string is guaranteed to be 0, thus Id for any non empty string is guaranteed to be non zero.
type Formatter ¶
type Formatter interface { io.Writer Format(format string, args ...interface{}) (n int, errno error) }
Formatter is an io.Writer extended by a fmt.Printf like function Format
func FlatFormatter ¶
FlatFormatter returns a newly created Formatter with the same functionality as the one returned by IndentFormatter except it allows a newline in the 'format' string argument of Format to pass through iff indent level is currently zero.
If indent level is non-zero then such new lines are changed to a space character. There is no indent string, the %i and %u format verbs are used solely to determine the indent level.
The FlatFormatter is intended for flattening of normally nested structure textual representation to a one top level structure per line form.
FlatFormatter(os.Stdout, " ").Format("abc%d%%e%i\nx\ny\n%uz\n", 3)
output in the form of a Go quoted string literal:
"abc3%%e x y z\n"
func IndentFormatter ¶
IndentFormatter returns a new Formatter which interprets %i and %u in the Format() format string as indent and undent commands. The commands can nest. The Formatter writes to io.Writer 'w' and inserts one 'indent' string per current indent level value. Behaviour of commands reaching negative indent levels is undefined.
IndentFormatter(os.Stdout, "\t").Format("abc%d%%e%i\nx\ny\n%uz\n", 3)
output:
abc3%e x y z
The Go quoted string literal form of the above is:
"abc%%e\n\tx\n\tx\nz\n"
The commands can be scattered between separate invocations of Format(), i.e. the formatter keeps track of the indent level and knows if it is positioned on start of a line and should emit indentation(s). The same output as above can be produced by e.g.:
f := IndentFormatter(os.Stdout, " ") f.Format("abc%d%%e%i\nx\n", 3) f.Format("y\n%uz\n")
type GoDict ¶
type GoDict struct {
// contains filtered or unexported fields
}
GoDict is a concurrent access safe version of Dict.
type GoPool ¶
type GoPool struct {
// contains filtered or unexported fields
}
GoPool is a concurrent access safe version of Pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool handles aligning of strings having equal values to the same string instance. Intended use is to conserve some memory e.g. where a large number of identically valued strings with non identical backing arrays may exists in several semantically distinct instances of some structs. Pool is *not* concurrent access safe. It doesn't handle common prefix/suffix aligning, e.g. having s1 == "abc" and s2 == "bc", s2 is not automatically aligned as s1[1:].