utils

package
v1.19.33-clash.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: GPL-3.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyOr

func EmptyOr[T comparable](v T, def T) T

func Filter

func Filter[T comparable](tSlice []T, filter func(t T) bool) []T

func GlobalID

func GlobalID(material string) (id [8]byte)

func ImmutableBytesFromString

func ImmutableBytesFromString(s string) []byte

ImmutableBytesFromString is equivalent to []byte(s), except that it uses the same memory backing s instead of making a heap-allocated copy. This is only valid if the returned slice is never mutated.

func Map

func Map[T any, N any](arr []T, block func(it T) N) []N

func MapHash

func MapHash(material string) uint64

func MustOK

func MustOK[T any](result T, ok bool) T

func MustSharedRegexp2

func MustSharedRegexp2(pattern string) *regexp2.Regexp

func NewUUIDV3

func NewUUIDV3(ns uuid.UUID, name string) (u uuid.UUID)

NewUUIDV3 returns a UUID based on the MD5 hash of the namespace UUID and name.

func NewUUIDV4

func NewUUIDV4() (u uuid.UUID)

NewUUIDV4 returns a new version 4 UUID.

Version 4 UUIDs contain 122 bits of random data.

func NewUUIDV5

func NewUUIDV5(ns uuid.UUID, name string) (u uuid.UUID)

NewUUIDV5 returns a UUID based on SHA-1 hash of the namespace UUID and name.

func Reverse

func Reverse(s string) string

func SharedRegexp2

func SharedRegexp2(pattern string) (*regexp2.Regexp, error)

func StringFromImmutableBytes

func StringFromImmutableBytes(bs []byte) string

StringFromImmutableBytes is equivalent to string(bs), except that it uses the same memory backing bs instead of making a heap-allocated copy. This is only valid if bs is never mutated after StringFromImmutableBytes returns.

func StringToBps

func StringToBps(s string) uint64

func ToStringSlice

func ToStringSlice(value any) ([]string, error)

Types

type Callback

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

func NewCallback

func NewCallback[T any]() *Callback[T]

func (*Callback[T]) Emit

func (c *Callback[T]) Emit(item T)

func (*Callback[T]) Register

func (c *Callback[T]) Register(item func(T)) io.Closer

type HashType

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

HashType warps hash array inside struct someday can change to other hash algorithm simply

func MakeHash

func MakeHash(data []byte) HashType

func (HashType) Bytes

func (h HashType) Bytes() []byte

func (HashType) Equal

func (h HashType) Equal(hash HashType) bool

func (HashType) IsValid

func (h HashType) IsValid() bool

func (HashType) Len

func (h HashType) Len() int

func (HashType) MarshalBinary

func (h HashType) MarshalBinary() ([]byte, error)

func (HashType) MarshalText

func (h HashType) MarshalText() ([]byte, error)

func (HashType) String

func (h HashType) String() string

func (*HashType) UnmarshalBinary

func (h *HashType) UnmarshalBinary(data []byte) error

func (*HashType) UnmarshalText

func (h *HashType) UnmarshalText(data []byte) error

type IntRanges

type IntRanges[T constraints.Integer] []Range[T]

func NewSignedRanges

func NewSignedRanges[T constraints.Signed](expected string) (IntRanges[T], error)

func NewSignedRangesFromList

func NewSignedRangesFromList[T constraints.Signed](list []string) (IntRanges[T], error)

func NewUnsignedRanges

func NewUnsignedRanges[T constraints.Unsigned](expected string) (IntRanges[T], error)

func NewUnsignedRangesFromList

func NewUnsignedRangesFromList[T constraints.Unsigned](list []string) (IntRanges[T], error)

func (IntRanges[T]) Check

func (ranges IntRanges[T]) Check(status T) bool

func (IntRanges[T]) Merge

func (ranges IntRanges[T]) Merge() (mergedRanges IntRanges[T])

func (IntRanges[T]) Range

func (ranges IntRanges[T]) Range(f func(t T) bool)

func (IntRanges[T]) String

func (ranges IntRanges[T]) String() string

type Range

type Range[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

func NewRange

func NewRange[T constraints.Ordered](start, end T) Range[T]

func NewSignedRange

func NewSignedRange[T constraints.Signed](expected string) (Range[T], error)

func NewUnsignedRange

func NewUnsignedRange[T constraints.Unsigned](expected string) (Range[T], error)

func (Range[T]) Contains

func (r Range[T]) Contains(t T) bool

func (Range[T]) End

func (r Range[T]) End() T

func (Range[T]) LeftContains

func (r Range[T]) LeftContains(t T) bool

func (Range[T]) RightContains

func (r Range[T]) RightContains(t T) bool

func (Range[T]) Start

func (r Range[T]) Start() T

func (Range[T]) String

func (r Range[T]) String() string

Jump to

Keyboard shortcuts

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