package strutil
import "k8s.io/kubernetes/Godeps/_workspace/src/github.com/cznic/strutil"
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 SplitFields(s, sep string) (flds []string)
- func StrPack(s string) string
- type Dict
- func NewDict() (d *Dict)
- func (d *Dict) Count() int
- func (d *Dict) Id(s string) (y int)
- func (d *Dict) S(id int) (s string, ok bool)
- type Formatter
- func FlatFormatter(w io.Writer) Formatter
- func IndentFormatter(w io.Writer, indent string) Formatter
- type GoDict
- func NewGoDict() (d *GoDict)
- func (d *GoDict) Count() int
- func (d *GoDict) Id(s string) (y int)
- func (d *GoDict) S(id int) (s string, ok bool)
- type GoPool
- func NewGoPool() (p *GoPool)
- func (p *GoPool) Align(s string) (y string)
- func (p *GoPool) Count() int
- type Pool
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 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.
func StrPack ¶
StrPack returns a new instance of s which is tightly packed in memory. It is intended for avoiding the situation where having a live reference to a string slice over an unreferenced biger underlying string keeps the biger one in memory anyway - it can't be GCed.
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.
func NewDict ¶
func NewDict() (d *Dict)
NewDict returns a newly created Dict.
func (*Dict) Count ¶
Count returns the number of items in the dict.
func (*Dict) Id ¶
Id maps string s to its numeric identificator.
func (*Dict) S ¶
S maps an id to its string value and ok == true. Id values not contained in the bijection return "", false.
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.
func NewGoDict ¶
func NewGoDict() (d *GoDict)
NewGoDict returns a newly created GoDict.
func (*GoDict) Count ¶
Count returns the number of items in the dict.
func (*GoDict) Id ¶
Id maps string s to its numeric identificator. The implementation honors getting an existing id at the cost of assigning a new one.
func (*GoDict) S ¶
S maps an id to its string value and ok == true. Id values not contained in the bijection return "", false.
type GoPool ¶
type GoPool struct {
// contains filtered or unexported fields
}
GoPool is a concurrent access safe version of Pool.
func NewGoPool ¶
func NewGoPool() (p *GoPool)
NewGoPool returns a newly created GoPool.
func (*GoPool) Align ¶
Align returns a string with the same value as its argument. It guarantees that all aligned strings share a single instance in memory.
func (*GoPool) Count ¶
Count returns the number of items in the 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:].
func NewPool ¶
func NewPool() *Pool
NewPool returns a newly created Pool.
func (*Pool) Align ¶
Align returns a string with the same value as its argument. It guarantees that all aligned strings share a single instance in memory.
func (*Pool) Count ¶
Count returns the number of items in the pool.
Source Files ¶
strutil.go
- Version
- v0.16.2
- Published
- May 4, 2015
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 32 seconds ago –
Tools for package owners.