strutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

auto-generated, DO NOT EDIT!

Index

Constants

This section is empty.

Variables

View Source
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

func CommaSeparatedList(str string) []string

CommaSeparatedList takes a comman-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

func Deduplicate(sl []string) []string

Deduplicate returns a newly allocated slice with the same contents as the input, excluding duplicates.

func ElliptLeft

func ElliptLeft(str string, n int) string

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

func ElliptRight(str string, n int) string

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 Intersection

func Intersection(slices ...[]string) []string

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

func IntsToCommaSeparated(vals []int) string

IntsToCommaSeparated converts an int array to a comma-separated string without whitespace

func ListContains

func ListContains(list []string, str string) bool

ListContains determines whether the given string is contained in the given list of strings.

func ParseByteSize

func ParseByteSize(inp string) (int64, error)

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

func Quoted(names []string) string

Quoted formats a slice of strings to a quoted list of comma-separated strings, e.g. `"snap1", "snap2"`

func SizeToStr

func SizeToStr(size int64) string

SizeToStr converts the given size in bytes to a readable string

func SortedListContains

func SortedListContains(list []string, str string) bool

SortedListContains determines whether the given string is contained in the given list of strings, which must be sorted.

func SortedListsUniqueMerge

func SortedListsUniqueMerge(sl1, sl2 []string) []string

SortedListsUniqueMerge merges the two given sorted lists of strings, repeated values will appear once in the result.

func SplitUnit

func SplitUnit(inp string) (number int64, unit string, err error)

SplitUnit takes a string of the form "123unit" and splits it into the number and non-number parts (123,"unit").

func TruncateOutput

func TruncateOutput(data []byte, maxLines, maxBytes int) []byte

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

func VersionCompare(va, vb string) (res int, err error)

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

func WordWrap

func WordWrap(out io.Writer, text []rune, indent, indent2 string, termWidth int) error

WordWrap wraps the given text to the given width, prefixing the first line with indent and the remaining lines with indent2

func WordWrapPadded

func WordWrapPadded(out io.Writer, text []rune, pad string, termWidth int) error

WordWrapPadded wraps the given text, assumed to be part of a block-style yaml string, to fit into termWidth, preserving the line's indent, and writes it out prepending padding to each line.

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

func (*LimitedBuffer) Write

func (lb *LimitedBuffer) Write(data []byte) (int, error)

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.

func (*MatchCounter) Write

func (w *MatchCounter) Write(p []byte) (int, error)

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) Copy

func (o *OrderedMap) Copy() *OrderedMap

Copy makes a copy of the map

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.CurrentName() with openat(2) family of functions.
   // Use iter.CurrentPath() or iter.CurrentBase() for context.
}

```

func NewPathIterator

func NewPathIterator(path string) (*PathIterator, error)

NewPathIterator returns an iterator for traversing the given path. The path is passed through filepath.Clean automatically.

func (*PathIterator) CurrentBase

func (iter *PathIterator) CurrentBase() string

CurrentBase returns the prefix of the path that was traversed, excluding the current name. The result never ends in '/' except if current base is root.

func (*PathIterator) CurrentCleanName

func (iter *PathIterator) CurrentCleanName() string

CurrentCleanName returns the same value as Name with right slash trimmed.

func (*PathIterator) CurrentName

func (iter *PathIterator) CurrentName() string

CurrentName returns the name of the current path element. The return value may end with '/'. Use CleanName to avoid that.

func (*PathIterator) CurrentPath

func (iter *PathIterator) CurrentPath() string

CurrentPath returns the prefix of path that was traversed, including the current name.

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) 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 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.

Directories

Path Synopsis
Package shlex implements a simple lexer which splits input in to tokens using shell-style rules for quoting and commenting.
Package shlex implements a simple lexer which splits input in to tokens using shell-style rules for quoting and commenting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL