lang

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidStartPosition = errors.New("start position is invalid")
	ErrInvalidStopPosition  = errors.New("stop position is invalid")
)

Functions

func BTS added in v0.4.4

func BTS(b []byte) string

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Camel2Snake

func Camel2Snake(s string) string

func Contains

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

func Filter

func Filter(s string, filter func(r rune) bool) string

func FuncFullName added in v0.4.3

func FuncFullName(fnc any) string

func FuncName added in v0.4.3

func FuncName(fnc any) string

func HasEmpty

func HasEmpty(args ...string) bool

func NotEmpty

func NotEmpty(args ...string) bool

func Ptr

func Ptr[T any](x T) *T

用泛型的方式获取一个值的地址

func RelevantCaller

func RelevantCaller(outsidePkg string) runtime.Frame

relevantCaller searches the call stack for the first function outside of pkg The purpose of this function is to provide more helpful error messages. how to use? example: caller := relevantCaller("net/http.") logx.Info("superfluous WriteHeader call from %s (%s:%d)", caller.Function, path.Base(caller.File), caller.Line)

func Remove

func Remove(strings []string, strs ...string) []string

func Reverse

func Reverse(s string) string

func Round32

func Round32(f float32, n int) float32

func Round64

func Round64(f float64, n int) float64

func STB added in v0.4.4

func STB(s string) (b []byte)

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func Substr

func Substr(str string, start int, stop int) (string, error)

Substr returns runes between start and stop [start, stop) regardless of the chars are ascii or utf8

func TakeOne

func TakeOne(valid, or string) string

func TakeWithPriority

func TakeWithPriority(fns ...func() string) string

func ToBool

func ToBool(v any) (b bool, err error)

func ToBytes

func ToBytes(stream any) (data []byte)

func ToDuration

func ToDuration(v any) (dr time.Duration, err error)

func ToFloat32

func ToFloat32(v any) (f32 float32, err error)

func ToFloat64

func ToFloat64(v any) (f64 float64, err error)

func ToInt

func ToInt(v any) (i int, err error)

func ToInt16

func ToInt16(v any) (i16 int16, err error)

func ToInt32

func ToInt32(v any) (i32 int32, err error)

func ToInt64

func ToInt64(v any) (i64 int64, err error)

任意类型的值,转换成 Int64,只要能转,不丢失精度都转,否则给出错误

func ToInt8

func ToInt8(v any) (i8 int8, err error)

func ToString

func ToString(v any) (s string)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func ToString2

func ToString2(v any) (s string, err error)

ToString 获取变量的字符串值 浮点型 3.0 将会转换成字符串3 -> "3", 非数值或字符类型的变量将会被转换成JSON格式字符串

func ToTime

func ToTime(layout string, v any) (tm *time.Time, err error)

func ToUint

func ToUint(v any) (ui uint, err error)

func ToUint16

func ToUint16(v any) (ui16 uint16, err error)

func ToUint32

func ToUint32(v any) (ui32 uint32, err error)

func ToUint64

func ToUint64(v any) (ui64 uint64, err error)

任意类型的值,转换成 Int64,只要能转,不丢失精度都转,否则给出错误

func ToUint8

func ToUint8(v any) (ui8 uint8, err error)

func Union

func Union(first, second []string) []string

Types

type PlaceholderType

type PlaceholderType = struct{}
var (
	ShareVal    PlaceholderType
	Placeholder PlaceholderType
)

type Replacer

type Replacer interface {
	Replace(text string) string
}

func NewReplacer

func NewReplacer(mapping map[string]string) Replacer

type Trie

type Trie interface {
	Filter(text string) (string, []string, bool)
	FindKeywords(text string) []string
}

func NewTrie

func NewTrie(words []string, opts ...TrieOption) Trie

type TrieOption

type TrieOption func(trie *trieNode)

func WithMask

func WithMask(mask rune) TrieOption

Jump to

Keyboard shortcuts

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