utilfn

package
v0.0.0-...-1234919 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 19 Imported by: 8

Documentation

Index

Constants

View Source
const LineDiffVersion = 0
View Source
const NoStrPos = -1

sentinel value for StrWithPos.Pos to indicate no position

Variables

View Source
var ErrOverflow = errors.New("integer overflow")
View Source
var HexDigits = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}

Functions

func AddInt

func AddInt(left, right int) (int, error)

Add two int values, returning an error if the result overflows.

func AddIntSlice

func AddIntSlice(vals ...int) (int, error)

Add a slice of ints, returning an error if the result overflows.

func AnsiGreenColor

func AnsiGreenColor() string

func AnsiRedColor

func AnsiRedColor() string

func AnsiResetColor

func AnsiResetColor() string

func AppendNonZeroRandomBytes

func AppendNonZeroRandomBytes(b []byte, randLen int) []byte

func ApplyDiff

func ApplyDiff(str1 string, diffBytes []byte) (string, error)

func ByteMapsEqual

func ByteMapsEqual(m1 map[string][]byte, m2 map[string][]byte) bool

func ChunkSlice

func ChunkSlice[T any](s []T, chunkSize int) [][]T

func CombineMaps

func CombineMaps[V any](m1 map[string]V, m2 map[string]V)

will overwrite m1 with m2's values

func CombineStrArrays

func CombineStrArrays(sarr1 []string, sarr2 []string) []string

combines string arrays and removes duplicates (returns a new array)

func ContainsStr

func ContainsStr(strs []string, test string) bool

func CopyToChannel

func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error

does *not* close outputCh on EOF or error

func CopyWithEndBytes

func CopyWithEndBytes(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte) (bool, error)

returns (isEOF, error)

func DecodeStringArray

func DecodeStringArray(barr []byte) ([]string, error)

func DecodeStringMap

func DecodeStringMap(barr []byte) (map[string]string, error)

func DetectMimeType

func DetectMimeType(path string) string

on error just returns "" does not return "application/octet-stream" as this is considered a detection failure

func EllipsisStr

func EllipsisStr(s string, maxLen int) string

func EncodeStringArray

func EncodeStringArray(arr []string) []byte

func EncodeStringMap

func EncodeStringMap(m map[string]string) []byte

func EncodedStringArrayGetFirstVal

func EncodedStringArrayGetFirstVal(encoded []byte) string

on encoding error returns "" this is used to perform logic on first value without decoding the entire array

func EncodedStringArrayHasFirstVal

func EncodedStringArrayHasFirstVal(encoded []byte, firstKey string) bool

func GetBool

func GetBool(v interface{}, field string) bool

func GetCmdExitCode

func GetCmdExitCode(cmd *exec.Cmd, err error) int

func GetExitCode

func GetExitCode(err error) int

func GetFirstLine

func GetFirstLine(s string) string

func GetMapKeys

func GetMapKeys[K comparable, V any](m map[K]V) []K

func GetOrderedMapKeys

func GetOrderedMapKeys[V any](m map[string]V) []string

func GetOrderedStringerMapKeys

func GetOrderedStringerMapKeys[K interface {
	comparable
	fmt.Stringer
}, V any](m map[K]V) []K

func GetStrArr

func GetStrArr(v interface{}, field string) []string

func IncSyncMap

func IncSyncMap[K comparable, V int | int64](sm *SyncMap[K, V], key K, incAmt V)

func IsPrefix

func IsPrefix(strs []string, test string) bool

func LongestPrefix

func LongestPrefix(root string, strs []string) string

func MakeDiff

func MakeDiff(str1 string, str2 string) []byte

func NullDecodeStr

func NullDecodeStr(barr []byte) (string, error)

func NullEncodeStr

func NullEncodeStr(s string) []byte

encodes a string, removing null/zero bytes (and separators '|') a zero byte is encoded as "\0", a '\' is encoded as "\\", sep is encoded as "\s" allows for easy double splitting (first on \x00, and next on "|")

func QuickJson

func QuickJson(v interface{}) string

func QuickParseJson

func QuickParseJson[T any](s string) T

func Sha1Hash

func Sha1Hash(data []byte) string

returns base64 hash of data

func ShellHexEscape

func ShellHexEscape(s string) string

returns hex escaped string (\xNN for each byte)

func ShellQuote

func ShellQuote(val string, forceQuote bool, maxLen int) string

minimum maxlen=6

func SortStringRunes

func SortStringRunes(s string) string

func StrArrayToMap

func StrArrayToMap(sarr []string) map[string]bool

func StrMapsEqual

func StrMapsEqual(m1 map[string]string, m2 map[string]string) bool

func StrsEqual

func StrsEqual(s1arr []string, s2arr []string) bool

Types

type LineDiffType

type LineDiffType struct {
	Lines   []int
	NewData []string
}

type StrWithPos

type StrWithPos struct {
	Str string `json:"str"`
	Pos int    `json:"pos"` // this is a 'rune' position (not a byte position)
}

func ParseToSP

func ParseToSP(s string) StrWithPos

func (StrWithPos) Append

func (sp StrWithPos) Append(str string) StrWithPos

func (StrWithPos) Prepend

func (sp StrWithPos) Prepend(str string) StrWithPos

func (StrWithPos) String

func (sp StrWithPos) String() string

type SyncMap

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func MakeSyncMap

func MakeSyncMap[K comparable, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) Clear

func (sm *SyncMap[K, V]) Clear()

func (*SyncMap[K, V]) Delete

func (sm *SyncMap[K, V]) Delete(k K)

func (*SyncMap[K, V]) Get

func (sm *SyncMap[K, V]) Get(k K) V

func (*SyncMap[K, V]) GetEx

func (sm *SyncMap[K, V]) GetEx(k K) (V, bool)

func (*SyncMap[K, V]) Keys

func (sm *SyncMap[K, V]) Keys() []K

func (*SyncMap[K, V]) Len

func (sm *SyncMap[K, V]) Len() int

func (*SyncMap[K, V]) Replace

func (sm *SyncMap[K, V]) Replace(newMap map[K]V)

func (*SyncMap[K, V]) Set

func (sm *SyncMap[K, V]) Set(k K, v V)

Jump to

Keyboard shortcuts

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