Documentation ¶
Overview ¶
auto-generated, DO NOT EDIT!
Index ¶
- Variables
- func CommaSeparatedList(str string) []string
- func Deduplicate(sl []string) []string
- func ElliptLeft(str string, n int) string
- func ElliptRight(str string, n int) string
- func FindCommonPrefix(patterns []string) (string, error)
- func Intersection(slices ...[]string) []string
- func IntsToCommaSeparated(vals []int) string
- func JoinNonEmpty(strs []string, sep string) string
- func ListContains(list []string, str string) bool
- func MultiCommaSeparatedList(strs []string) []string
- func ParseByteSize(inp string) (int64, error)
- func Quoted(names []string) string
- func SizeToStr(size int64) string
- func SortedListContains(list []string, str string) bool
- func SortedListsUniqueMerge(sl1, sl2 []string) []string
- func SplitUnit(inp string) (number int64, unit string, err error)
- func TruncateOutput(data []byte, maxLines, maxBytes int) []byte
- func VersionCompare(va, vb string) (res int, err error)
- func WordWrap(out io.Writer, text []rune, indent, indent2 string, termWidth int) error
- func WordWrapPadded(out io.Writer, text []rune, pad string, termWidth int) error
- type LimitedBuffer
- type MatchCounter
- type OrderedMap
- type OrderedSet
- type PathIterator
- func (iter *PathIterator) CurrentBase() string
- func (iter *PathIterator) CurrentDir() string
- func (iter *PathIterator) CurrentPath() string
- func (iter *PathIterator) CurrentPathPlusSlash() string
- func (iter *PathIterator) Depth() int
- func (iter *PathIterator) IsCurrentBaseLeaf() bool
- func (iter *PathIterator) Next() bool
- func (iter *PathIterator) Path() string
- func (iter *PathIterator) Rewind()
Constants ¶
This section is empty.
Variables ¶
var Ctrl = &unicode.RangeTable{ R16: []unicode.Range16{ {Lo: 0x00ad, Hi: 0x0600, Stride: 1363}, {Lo: 0x0601, Hi: 0x0605, Stride: 1}, {Lo: 0x061c, Hi: 0x06dd, Stride: 193}, {Lo: 0x070f, Hi: 0x08e2, Stride: 467}, {Lo: 0x180e, Hi: 0x200b, Stride: 2045}, {Lo: 0x200c, Hi: 0x200f, Stride: 1}, {Lo: 0x202a, Hi: 0x202e, Stride: 1}, {Lo: 0x2060, Hi: 0x2064, Stride: 1}, {Lo: 0x2066, Hi: 0x206f, Stride: 1}, {Lo: 0xd800, Hi: 0xf8ff, Stride: 1}, {Lo: 0xfdd0, Hi: 0xfdef, Stride: 1}, {Lo: 0xfeff, Hi: 0xfff9, Stride: 250}, {Lo: 0xfffa, Hi: 0xfffb, Stride: 1}, {Lo: 0xfffe, Hi: 0xffff, Stride: 1}, }, R32: []unicode.Range32{ {Lo: 0x110bd, Hi: 0x1bca0, Stride: 44003}, {Lo: 0x1bca1, Hi: 0x1bca3, Stride: 1}, {Lo: 0x1d173, Hi: 0x1d17a, Stride: 1}, {Lo: 0x1fffe, Hi: 0x1ffff, Stride: 1}, {Lo: 0x2fffe, Hi: 0x2ffff, Stride: 1}, {Lo: 0x3fffe, Hi: 0x3ffff, Stride: 1}, {Lo: 0x4fffe, Hi: 0x4ffff, Stride: 1}, {Lo: 0x5fffe, Hi: 0x5ffff, Stride: 1}, {Lo: 0x6fffe, Hi: 0x6ffff, Stride: 1}, {Lo: 0x7fffe, Hi: 0x7ffff, Stride: 1}, {Lo: 0x8fffe, Hi: 0x8ffff, Stride: 1}, {Lo: 0x9fffe, Hi: 0x9ffff, Stride: 1}, {Lo: 0xafffe, Hi: 0xaffff, Stride: 1}, {Lo: 0xbfffe, Hi: 0xbffff, Stride: 1}, {Lo: 0xcfffe, Hi: 0xcffff, Stride: 1}, {Lo: 0xdfffe, Hi: 0xdffff, Stride: 1}, {Lo: 0xe0001, Hi: 0xe0020, Stride: 31}, {Lo: 0xe0021, Hi: 0xe007f, Stride: 1}, {Lo: 0xefffe, Hi: 0x10ffff, Stride: 1}, }, }
using golang.org/x/text/unicode/rangetable do rangetable.Merge(unicode.Co, unicode.Cf, unicode.Cs, unicode.Noncharacter_Code_Point) (we also care about unicode.Cc but that's handled by hand) this makes the lookup in escape quite a bit faster (over 5×)
Functions ¶
func CommaSeparatedList ¶
CommaSeparatedList takes a comma-separated series of identifiers, and returns a slice of the space-trimmed identifiers, without empty entries. So " foo ,, bar,baz" -> {"foo", "bar", "baz"}
func Deduplicate ¶
Deduplicate returns a newly allocated slice with the same contents as the input, excluding duplicates.
func ElliptLeft ¶
ElliptLeft returns a string that is at most n runes long, replacing the first rune with an ellipsis if necessary. If N is less than 1 it's treated as a 1.
func ElliptRight ¶
ElliptRight returns a string that is at most n runes long, replacing the last rune with an ellipsis if necessary. If N is less than 1 it's treated as a 1.
func FindCommonPrefix ¶
func Intersection ¶
Intersection computes the intersection of a set of slices, treating each slice as a set. It does not mutate any of the input slices and returns a new slice. It is recursive.
func IntsToCommaSeparated ¶
IntsToCommaSeparated converts an int array to a comma-separated string without whitespace
func JoinNonEmpty ¶
JoinNonEmpty concatenates non-empty strings using sep as separator, and trimming sep from beginning and end of the strings. This overcomes a problem with strings.Join, which will introduce separators for empty strings.
func ListContains ¶
ListContains determines whether the given string is contained in the given list of strings.
func MultiCommaSeparatedList ¶
MultiCommaSeparatedList parses each string in strs with CommaSeparatedList and returns the concatenation of all parsed values.
func ParseByteSize ¶
ParseByteSize parses a value like 500kB and returns the number in bytes. The case of the unit will be ignored for user convenience.
func Quoted ¶
Quoted formats a slice of strings to a quoted list of comma-separated strings, e.g. `"snap1", "snap2"`
func SortedListContains ¶
SortedListContains determines whether the given string is contained in the given list of strings, which must be sorted.
func SortedListsUniqueMerge ¶
SortedListsUniqueMerge merges the two given sorted lists of strings, repeated values will appear once in the result.
func SplitUnit ¶
SplitUnit takes a string of the form "123unit" and splits it into the number and non-number parts (123,"unit").
func TruncateOutput ¶
TruncateOutput truncates input data by maxLines, imposing maxBytes limit (total) for them. The maxLines may be 0 to avoid the constraint on number of lines.
func VersionCompare ¶
VersionCompare compare two version strings that follow the debian version policy and Returns:
-1 if a is smaller than b 0 if a equals b +1 if a is bigger than b
Types ¶
type LimitedBuffer ¶
type LimitedBuffer struct {
// contains filtered or unexported fields
}
func NewLimitedBuffer ¶
func NewLimitedBuffer(maxLines, maxBytes int) *LimitedBuffer
func (*LimitedBuffer) Bytes ¶
func (lb *LimitedBuffer) Bytes() []byte
type MatchCounter ¶
type MatchCounter struct { // Regexp to use to find matches in the stream Regexp *regexp.Regexp // Maximum number of matches to keep; if < 0, keep all matches N int // LastN when true indicates that only N last matches shall be kept. LastN bool // contains filtered or unexported fields }
A MatchCounter is a discarding io.Writer that retains up to N matches to its Regexp before just counting matches.
It does not work with regexps that cross newlines; in fact it will probably not work if the data written isn't line-orineted.
If Regexp is not set (or nil), it matches whole non-empty lines.
func (*MatchCounter) Matches ¶
func (w *MatchCounter) Matches() ([]string, int)
Matches returns the first few matches, and the total number of matches seen.
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
OrderedMap is a map of strings to strings that preserves the insert order when calling "Keys()".
Heavily based on the spread.Environment code (thanks for that!)
func NewOrderedMap ¶
func NewOrderedMap(pairs ...string) *OrderedMap
NewOrderedMap creates a new ordered map initialized with the given pairs of strings.
func (*OrderedMap) Del ¶
func (o *OrderedMap) Del(key string)
Del removes the given key from the data structure
func (*OrderedMap) Get ¶
func (o *OrderedMap) Get(k string) string
Get returns the value for the given key
func (*OrderedMap) Keys ¶
func (o *OrderedMap) Keys() []string
Keys returns a list of keys in the map sorted by insertion order
func (*OrderedMap) Set ¶
func (o *OrderedMap) Set(k, v string)
Set adds the given key, value to the map. If the key already exists it is removed and the new value is put on the end.
func (*OrderedMap) UnmarshalYAML ¶
func (o *OrderedMap) UnmarshalYAML(u func(interface{}) error) error
UnmarshalYAML unmarshals a yaml string map and preserves the order
type OrderedSet ¶
type OrderedSet struct {
// contains filtered or unexported fields
}
OrderedSet is a set of strings that maintains the order of insertion.
The order of putting items into the set is retained. Putting items "a", "b" and then "a", results in order "a", "b".
External synchronization is required for safe concurrent access.
func (*OrderedSet) Contains ¶
func (o *OrderedSet) Contains(item string) bool
Contains returns true if the set contains a given item.
Contains is O(1) in the size of the set.
func (*OrderedSet) IndexOf ¶
func (o *OrderedSet) IndexOf(item string) (idx int, ok bool)
IndexOf returns the position of an item in the set.
func (*OrderedSet) Items ¶
func (o *OrderedSet) Items() []string
Items returns a slice of strings representing insertion order.
Items is O(N) in the size of the set.
func (*OrderedSet) Put ¶
func (o *OrderedSet) Put(item string)
Put adds an item into the set.
If the item was not present then it is stored and ordered after all existing elements. If the item was already present its position is not changed.
Put is O(1) in the size of the set.
func (*OrderedSet) Size ¶
func (o *OrderedSet) Size() int
Size returns the number of elements in the set.
type PathIterator ¶
type PathIterator struct {
// contains filtered or unexported fields
}
PathIterator traverses through parts (directories and files) of some path. The filesystem is never consulted, traversal is done purely in memory.
The iterator is useful in implementing secure traversal of absolute paths using the common idiom of opening the root directory followed by a chain of openat calls.
A simple example on how to use the iterator: ``` iter := NewPathIterator(path)
for iter.Next() { // Use iter.CurrentBase() with openat(2) family of functions. // Use iter.CurrentPath() or iter.CurrentDir() for context. }
```
func NewPathIterator ¶
func NewPathIterator(path string) (*PathIterator, error)
NewPathIterator returns an iterator for traversing the given path. The path must be clean (except for a possible trailing slash).
func (*PathIterator) CurrentBase ¶
func (iter *PathIterator) CurrentBase() string
CurrentBase returns the last element of the current path. It removes any trailing slash unless the last element of the current path is the filesystem root. Before any iteration with Next, CurrentBase returns an empty string. Example:
iter := NewPathIterator("/foo/bar") // iter.CurrentBase() == "" iter.Next() // iter.CurrentBase() == "/" && iter.CurrentPath() == "/" iter.Next() // iter.CurrentBase() == "foo" && iter.CurrentPath() == "/foo" iter.Next() // iter.CurrentBase() == "bar" && iter.CurrentPath() == "/foo/bar"
func (*PathIterator) CurrentDir ¶
func (iter *PathIterator) CurrentDir() string
CurrentDir returns all but the last element of the current path. The result always removes a trailing slash unless CurrentDir is the filesystem root. If the current path is empty because either Next has not yet been called or the current path only contains one element, then CurrentDir will return an empty string. Example:
iter := NewPathIterator("/foo/bar") // iter.CurrentDir() == "" iter.Next() // iter.CurrentDir() == "" && iter.CurrentPath() == "/" iter.Next() // iter.CurrentDir() == "/" && iter.CurrentPath() == "/foo" iter.Next() // iter.CurrentDir() == "/foo" && iter.CurrentPath() == "/foo/bar"
Example:
iter := NewPathIterator("foo/bar") // iter.CurrentDir() == "" iter.Next() // iter.CurrentDir() == "" && iter.CurrentPath() == "foo" iter.Next() // iter.CurrentDir() == "foo" && iter.CurrentPath() == "foo/bar"
func (*PathIterator) CurrentPath ¶
func (iter *PathIterator) CurrentPath() string
CurrentPath returns the path up to the current depth. Before any iteration with Next, CurrentPath returns an empty string. Example:
iter := NewPathIterator("/foo/bar") // iter.CurrentPath() == "" iter.Next() // iter.CurrentPath() == "/" && iter.Depth() == 1 iter.Next() // iter.CurrentPath() == "/foo" && iter.Depth() == 2 iter.Next() // iter.CurrentPath() == "/foo/bar" && iter.Depth() == 3
func (*PathIterator) CurrentPathPlusSlash ¶
func (iter *PathIterator) CurrentPathPlusSlash() string
Adds a trailing slash to the current path even if the current path does not have one. Before any iteration with Next, CurrentPathPlusSlash returns an empty string. Example:
iter := NewPathIterator("/foo/bar") // iter.CurrentPathPlusSlash() == "" iter.Next() // iter.CurrentPathPlusSlash() == "/" iter.Next() // iter.CurrentPathPlusSlash() == "/foo/" iter.Next() // iter.CurrentPathPlusSlash() == "/foo/bar/"
func (*PathIterator) Depth ¶
func (iter *PathIterator) Depth() int
Depth returns the directory depth of the current path.
This is equal to the number of traversed directories, including that of the root directory.
func (*PathIterator) IsCurrentBaseLeaf ¶
func (iter *PathIterator) IsCurrentBaseLeaf() bool
IsCurrentBaseLeaf returns true if CurrentBase is the leaf of the path. Example:
iter := NewPathIterator("foo/bar") // iter.IsCurrentBaseLeaf() == false iter.Next() // iter.CurrentBase() == "foo" && iter.IsCurrentBaseLeaf() == false iter.Next() // iter.CurrentBase() == "bar" && iter.IsCurrentBaseLeaf() == true
func (*PathIterator) Next ¶
func (iter *PathIterator) Next() bool
Next advances the iterator to the next name, returning true if one is found.
If this method returns false then no change is made and all helper methods retain their previous return values.
func (*PathIterator) Path ¶
func (iter *PathIterator) Path() string
Path returns the entire path being traversed.
func (*PathIterator) Rewind ¶
func (iter *PathIterator) Rewind()
Rewind returns the iterator to the initial state, allowing the path to be traversed again.