utils

package
v0.0.0-...-10a9de3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: MIT Imports: 16 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesByteAt

func BytesByteAt(s string, index int) byte

func BytesIndexByteOrLen

func BytesIndexByteOrLen(s []byte, c byte) int

func BytesToStrings

func BytesToStrings(b [][]byte) []string

func CleanUpRegexp

func CleanUpRegexp(pattern string) string

Remove whitespace and comments from a regex pattern.

func Clip

func Clip(n, start, last int) int

func Clip32

func Clip32(n, start, last int32) int32

func Clip64

func Clip64(n, start, last int64) int64

func DoAndEnsure

func DoAndEnsure(fun func(), ensure func())

func FirstNonEmpty

func FirstNonEmpty(vals ...string) string

func GoMulti

func GoMulti(n int, f func()) func()

func HomeExpanded

func HomeExpanded(path string) string

func IndexByteOrLen

func IndexByteOrLen(s string, c byte) int

func Iter

func Iter[T any](array []T) func() *T

Iter returns a function that returns elements in a given array, or return nil at the end.

func LessToCmp

func LessToCmp[E cmp.Ordered](less func(E, E) bool) func(E, E) int

func MustExec

func MustExec(args []string)

MustExec is a must-version of syscall.Exec.

func MustParseFloat32

func MustParseFloat32(val string) float32

func MustParseFloat64

func MustParseFloat64(val string) float64

func MustParseInt

func MustParseInt(val string, base int) int

func MustParseInt32

func MustParseInt32(val string, base int) int32

func MustParseInt64

func MustParseInt64(val string, base int) int64

func ParseFloat32

func ParseFloat32(val string, defaultValue float32) float32

func ParseFloat64

func ParseFloat64(val string, defaultValue float64) float64

func ParseInt

func ParseInt(val string, base int, defaultValue int) int

func ParseInt32

func ParseInt32(val string, base int, defaultValue int32) int32

func ParseInt64

func ParseInt64(val string, base int, defaultValue int64) int64

func ReadPdfAsText

func ReadPdfAsText(file string, keepLayout bool) ([]byte, error)

ReadPdfAsText reads a given PDF file as text.

func SortedMap

func SortedMap[K cmp.Ordered, V any](m map[K]V) iter.Seq2[K, V]

func SortedMapFunc

func SortedMapFunc[K cmp.Ordered, V any](m map[K]V, compare func(K, K) int) iter.Seq2[K, V]

func StringByteAt

func StringByteAt(s string, index int) byte

func StringSlice

func StringSlice(arr ...string) []string

StringSlice is a convenient way to build a string slice.

func StringsToBytes

func StringsToBytes(s []string) [][]byte

func Wrap

func Wrap(n, len int) int

func Wrap32

func Wrap32(n, len int32) int32

func Wrap64

func Wrap64(n, len int64) int64

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock is a mockable clock interface.

func NewClock

func NewClock() Clock

Create a new (real) Clock.

func NewInjectedClock

func NewInjectedClock(time time.Time) Clock

NewInjectedClock creates a new mock clock.

type InjectedClock

type InjectedClock struct {
	// contains filtered or unexported fields
}

InjectedClock is a mock clock.

func (InjectedClock) Now

func (c InjectedClock) Now() time.Time

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator is a versatile iterator.

func NewIterable

func NewIterable[T any](nextFetcher func() (*T, bool), cleaner func()) *Iterator[T]

NewIterable creates a new Iterable, with an optional cleaner, which is called at the end.

func (*Iterator[T]) Close

func (i *Iterator[T]) Close()

func (*Iterator[T]) Next

func (i *Iterator[T]) Next() (element *T, ok bool)

Next returns a next element.

type LazyRegexp

type LazyRegexp struct {
	// contains filtered or unexported fields
}

LazyRegexp is a sharable lazily compiled regexp.

func NewLazyRegexp

func NewLazyRegexp(pattern string) LazyRegexp

NewLazyRegexp returns a sharable lazily compiled regexp.

func (*LazyRegexp) Pattern

func (l *LazyRegexp) Pattern() *regexp.Regexp

Pattern returns a shared regexp.

Jump to

Keyboard shortcuts

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