types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 字母 + 数字,移除 il o0
	CHARS string = `abcdefghjkmnpqrstuvwxyz123456789`

	// 纯字母,移除 il
	PURE_LETTER_CHARS string = `abcdefghjkmnopqrstuvwxyz`

	// 纯数字字符
	PURE_NUMBER_CHARS string = `0123456789`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyType

type AnyType struct{}

func (AnyType) Float

func (at AnyType) Float(fromVal any, toVal *float64) (err error)

Float 将 any 类型的值转换为 float64 类型的值。 支持以下类型:uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, float32, float64, string(可以是浮点数字符串)。

func (AnyType) If

func (at AnyType) If(isTrue bool, trueValue, falseValue any) any

If 根据条件判断返回不同的值。

func (AnyType) InArray

func (at AnyType) InArray(item, stack any) bool

Return true if stack has the element item, return false otherwise 由于使用了反射,可能在性能上有一定的负担,并且由于没有类型检查,不能有效地避免类型不匹配的情况 不推荐使用这种方式,请转换为具体类型后执行类型下的 InArray

func (AnyType) Int

func (at AnyType) Int(fromVal any, toVal *int) error

Int 将 any 类型的值转换为 int 类型的值。 支持以下类型:uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, float32, float64, string(可以是 10 进制数字字符串)。

func (AnyType) Int64

func (at AnyType) Int64(fromVal any, toValue *int64) (err error)

Int64 将 any 类型的值转换为 int64 类型的值。 支持以下类型:uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, float32, float64, string(可以是 10 进制数字字符串)。 注:float 类型转换时将损失精度,所以请传入 1111.0 这样不会损失精度的值

func (AnyType) Int64Array

func (at AnyType) Int64Array(arr []any, dstArr *[]int64) error

any 数组转为 int64 数组

func (AnyType) StructTo

func (at AnyType) StructTo(src, dst any) error

结构转换, 使用src内所有kv关系,对dst进行赋值 src: struct dst: struct pointer

func (AnyType) Uint

func (at AnyType) Uint(fromVal any, toVal *uint) error

Uint 将 any 类型的值转换为 uint 类型的值。 支持以下类型:uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, float32, float64, string(可以是 10 进制数字字符串)。

func (AnyType) Uint64

func (at AnyType) Uint64(fromVal any, toValue *uint64) (err error)

Uint64 将 any 类型的值转换为 uint64 类型的值。 支持以下类型:uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, float32, float64, string(可以是 10 进制数字字符串)。

func (AnyType) Uint64Array

func (at AnyType) Uint64Array(arr []any, dstArr *[]uint64) error

any 数组转为 uint64 数组

type BoolType

type BoolType struct{}

func (BoolType) And

func (bt BoolType) And(values ...bool) bool

And 对 bool 类型进行逻辑与操作。

func (BoolType) If

func (bt BoolType) If(isTrue, trueValue, falseValue bool) bool

If 根据条件判断返回不同的值。

func (BoolType) Not

func (bt BoolType) Not(value bool) bool

Not 对 bool 类型进行逻辑非操作。

func (BoolType) Or

func (bt BoolType) Or(values ...bool) bool

Or 对 bool 类型进行逻辑或操作。

type FloatType

type FloatType struct{}

func (FloatType) Abs

func (ft FloatType) Abs(value float64) float64

Abs 返回浮点数的绝对值。

func (FloatType) ArrayAsc

func (ft FloatType) ArrayAsc(arr []float64)

数组排序 asc

func (FloatType) ArrayDesc

func (ft FloatType) ArrayDesc(arr []float64)

数组排序 desc

func (FloatType) Avg

func (ft FloatType) Avg(values ...float64) float64

Avg 计算浮点数数组中所有值的平均值。

func (FloatType) BinFind

func (ft FloatType) BinFind(value float64, arr []float64, isAsc bool) int

二分查找数组

此函数适用于数组值已排序或将对同一数组进行多次查找,传入已排序的数组以提高效率。 注:若传入未排序的数组,结果可能并不符合预期。

成功时返回查找到的数组下标,失败返回 -1

func (FloatType) BinSearch

func (ft FloatType) BinSearch(value float64, arr []float64, isAsc bool) int

二分查找(此函数不会进行排序,请输入已排序的数组,否则会产生非预期结果) 成功返回查找到的数组下标,失败返回 -1

func (FloatType) Ceil

func (ft FloatType) Ceil(value float64) float64

Ceil 返回不小于 value 的最小整数,也就是向上取整。

func (FloatType) Find

func (ft FloatType) Find(value float64, arr []float64) int

查找数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

二分查找时,将会对数组进行升序排序,查找成功返回的也会是升序后的下标

成功时返回查找到的数组下标,失败返回 -1

func (FloatType) FindSorted

func (ft FloatType) FindSorted(value float64, arr []float64, isAsc bool) int

查找已排序数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

成功时返回查找到的数组下标,失败返回 -1

func (FloatType) Floor

func (ft FloatType) Floor(value float64) float64

Floor 返回不大于 value 的最大整数,也就是向下取整。

func (FloatType) If

func (ft FloatType) If(isTrue bool, trueValue, falseValue float64) float64

If 根据条件判断返回不同的值。

func (FloatType) InArray

func (ft FloatType) InArray(value float64, arr []float64) bool

浮点数切片查找,threshold 参数生效

func (FloatType) InSortedArray

func (ft FloatType) InSortedArray(value float64, arr []float64, isAsc bool) bool

已排序数组查找,threshold 参数生效

func (FloatType) LoopFind

func (ft FloatType) LoopFind(value float64, arr []float64) int

遍历查找数组

如果数组长度较长或对同一数组做多次 LoopFind,建议先 ArrayAsc 后使用 BinFind

成功时返回查找到的数组下标,失败返回 -1

func (FloatType) Max

func (ft FloatType) Max(values ...float64) float64

Max 获取浮点数数组中的最大值。

func (FloatType) Min

func (ft FloatType) Min(values ...float64) float64

Min 获取浮点数数组中的最小值。

func (FloatType) Round

func (ft FloatType) Round(value float64, places int) float64

Round 对浮点数进行四舍五入操作,places 参数表示小数点后保留位数。

func (FloatType) SortAndBinSearch

func (ft FloatType) SortAndBinSearch(value float64, arr []float64) int

对数组排序并进行二分查找法,成功返回查找到的数组下标,失败返回 -1

func (FloatType) Str

func (ft FloatType) Str(value float64) string

Str 将浮点类型的值转换为字符串类型的值。

func (FloatType) Sum

func (ft FloatType) Sum(values ...float64) float64

Sum 计算浮点数数组中所有值的总和。

type IntType

type IntType struct{}

func (IntType) Abs

func (it IntType) Abs(value int64) int64

Abs:获取 int64 类型的值的绝对值。

func (IntType) ArrayAsc

func (it IntType) ArrayAsc(arr []int64)

数组排序 asc

func (IntType) ArrayDesc

func (it IntType) ArrayDesc(arr []int64)

数组排序 desc

func (IntType) Avg

func (it IntType) Avg(values ...int64) float64

Avg:计算 int64 类型的值数组中所有值的平均值。

func (IntType) BinFind

func (it IntType) BinFind(value int64, arr []int64, isAsc bool) int

二分查找数组

此函数适用于数组值已排序或将对同一数组进行多次查找,传入已排序的数组以提高效率。 注:若传入未排序的数组,结果可能并不符合预期。

成功时返回查找到的数组下标,失败返回 -1

func (IntType) BinSearch

func (it IntType) BinSearch(value int64, arr []int64, isAsc bool) int

二分查找(此函数不会进行排序,请输入已排序的数组,否则会产生非预期结果) 成功返回查找到的数组下标,失败返回 -1

func (IntType) ConvertTo

func (it IntType) ConvertTo(from int64, toVal any) error

将 int64 类型转换为 其他int 类型, 仅限int类型内转换

toVal 必须为 int相关类型的指针 eg.

var val int8
if err := ConvertTo(12, &val); err != nil {}

func (IntType) Find

func (it IntType) Find(value int64, arr []int64) int

查找数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

二分查找时,将会对数组进行升序排序,查找成功返回的也会是升序后的下标

成功时返回查找到的数组下标,失败返回 -1

func (IntType) FindSorted

func (it IntType) FindSorted(value int64, arr []int64, isAsc bool) int

查找已排序数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

成功时返回查找到的数组下标,失败返回 -1

func (IntType) If

func (it IntType) If(isTrue bool, trueValue, falseValue int64) int64

If 根据条件判断返回不同的值。

func (IntType) InArray

func (it IntType) InArray(value int64, arr []int64) bool

整数切片查找,threshold 参数生效

func (IntType) InInt16Range

func (it IntType) InInt16Range(val int64) bool

判断给定的整数是否在 int16 范围内

func (IntType) InInt32Range

func (it IntType) InInt32Range(val int64) bool

判断给定的整数是否在 int32 范围内

func (IntType) InInt8Range

func (it IntType) InInt8Range(val int64) bool

判断给定的整数是否在 int8 范围内

func (IntType) InIntRange

func (it IntType) InIntRange(val int64) bool

判断给定的整数是否在 int 范围内

func (IntType) InRange

func (it IntType) InRange(value, min, max int64) bool

实现判断指定的 int64 类型值是否在指定的范围内的功能,返回布尔值

func (IntType) InSortedArray

func (it IntType) InSortedArray(value int64, arr []int64, isAsc bool) bool

已排序数组查找,threshold 参数生效

func (IntType) InUint16Range

func (it IntType) InUint16Range(val int64) bool

判断给定的整数是否在 uint16 范围内

func (IntType) InUint32Range

func (it IntType) InUint32Range(val int64) bool

判断给定的整数是否在 uint32 范围内

func (IntType) InUint64Range

func (it IntType) InUint64Range(val int64) bool

判断给定的整数是否在 uint64 范围内

func (IntType) InUint8Range

func (it IntType) InUint8Range(val int64) bool

判断给定的整数是否在 uint8 范围内

func (IntType) InUintRange

func (it IntType) InUintRange(val int64) bool

判断给定的整数是否在 uint 范围内

func (IntType) IsEven

func (it IntType) IsEven(value int64) bool

实现判断指定的 int64 类型值是否为偶数的功能,返回布尔值

func (IntType) IsOdd

func (it IntType) IsOdd(value int64) bool

实现判断指定的 int64 类型值是否为奇数的功能,返回布尔值

func (IntType) LoopFind

func (it IntType) LoopFind(value int64, arr []int64) int

遍历查找数组

如果数组长度较长或对同一数组做多次 LoopFind,建议先 ArrayAsc 后使用 BinFind

成功时返回查找到的数组下标,失败返回 -1

func (IntType) Max

func (it IntType) Max(values ...int64) int64

Max:获取 int64 类型的值数组中的最大值。

func (IntType) Min

func (it IntType) Min(values ...int64) int64

Min:获取 int64 类型的值数组中的最小值。

func (IntType) SortAndBinSearch

func (it IntType) SortAndBinSearch(value int64, arr []int64) int

对数组排序并进行二分查找法,成功返回查找到的数组下标,失败返回 -1

func (IntType) Str

func (it IntType) Str(value int64) string

Str:将 int64 类型的值转换为字符串类型的值。

func (IntType) Sum

func (it IntType) Sum(values ...int64) int64

Sum:计算 int64 类型的值数组中所有值的总和。

type StrType

type StrType struct{}

func (StrType) ArrayAsc

func (st StrType) ArrayAsc(arr []string)

func (StrType) ArrayDesc

func (st StrType) ArrayDesc(arr []string)

func (StrType) BinFind

func (st StrType) BinFind(value string, arr []string, isAsc bool) int

二分查找数组

此函数适用于数组值已排序或将对同一数组进行多次查找,传入已排序的数组以提高效率。 注:若传入未排序的数组,结果可能并不符合预期。

成功时返回查找到的数组下标,失败返回 -1

func (StrType) BinSearch

func (st StrType) BinSearch(value string, arr []string, isAsc bool) int

二分查找(此函数不会进行排序,请输入已排序的数组,否则会产生非预期结果) 成功返回查找到的数组下标,失败返回 -1

func (StrType) Bool

func (st StrType) Bool(str string, errBool bool) bool

string 转 bool, 需设置转换错误时的默认值

func (StrType) Find

func (st StrType) Find(value string, arr []string) int

查找数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

二分查找时,将会对数组进行升序排序,查找成功返回的也会是升序后的下标

成功时返回查找到的数组下标,失败返回 -1

func (StrType) FindSorted

func (st StrType) FindSorted(value string, arr []string, isAsc bool) int

查找已排序数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

成功时返回查找到的数组下标,失败返回 -1

func (StrType) Float

func (st StrType) Float(str string, errValue float64) float64

Covert string to positive int using strconv.Atoi(), return errValue if err != nil or value <= 0

func (StrType) Format

func (st StrType) Format(format string, a ...any) string

格式化字符串,类似 fmt.Sprintf()

func (StrType) HasPrefix

func (st StrType) HasPrefix(str, prefix string) bool

判断字符串 str 是否以 prefix 开头

func (StrType) HasSuffix

func (st StrType) HasSuffix(str, suffix string) bool

判断字符串 str 是否以 suffix 结尾

func (StrType) If

func (st StrType) If(boolValue bool, trueValue, falseValue string) string

Return string param trueValue if boolValue=true, return string param falseValue otherwise

func (StrType) InArray

func (st StrType) InArray(value string, arr []string) bool

字符串切片查找,threshold 参数生效

func (StrType) InSortedArray

func (st StrType) InSortedArray(value string, arr []string, isAsc bool) bool

已排序数组查找,threshold 参数生效

func (StrType) Index

func (st StrType) Index(str, substr string) int

查找字符串 substr 在 str 中首次出现的位置,如果找不到返回 -1

func (StrType) Int

func (st StrType) Int(str string, errValue int) int

string 转 int, 需设置转换错误时的默认值

func (StrType) IsEmpty

func (st StrType) IsEmpty(value string) bool

func (StrType) IsInt

func (st StrType) IsInt(str string) bool

func (StrType) IsNum

func (st StrType) IsNum(str string) bool

func (StrType) Join

func (st StrType) Join(strs []string, sep string) string

以 sep 为分隔符拼接字符串数组为一个字符串,同 strings.Join()

func (StrType) Len

func (st StrType) Len(str string) int

返回字符串的长度

func (StrType) LoopFind

func (st StrType) LoopFind(value string, arr []string) int

遍历查找数组

如果数组长度较长或对同一数组做多次 LoopFind,建议先 ArrayAsc 后使用 BinFind

成功时返回查找到的数组下标,失败返回 -1

func (StrType) LowerFirst

func (st StrType) LowerFirst(str string) string

将字符串首字母小写

func (StrType) Ltrim

func (st StrType) Ltrim(str, charsets string) string

将字符串左侧指定字符集合 charsets 中的字符去除

func (StrType) Pint

func (st StrType) Pint(str string, errValue uint) uint

Covert string to positive int using strconv.Atoi(), return errValue if err != nil or value <= 0

func (StrType) Rand

func (st StrType) Rand(length int) string

Generate random str base on letter&number mixed chars

func (StrType) RandChars

func (st StrType) RandChars(chars string, length int) (str string)

Generate random str base on baseChars

func (StrType) RandLetters

func (st StrType) RandLetters(length int) string

Generate random str base on letter chars

func (StrType) RandNumbers

func (st StrType) RandNumbers(length int) string

Generate random str base on number chars

func (StrType) RegReplace

func (st StrType) RegReplace(baseStr, regexpPattern, replacement string) string

Replace baseStr with regexpPattern to replacement

func (StrType) Replace

func (st StrType) Replace(str, old, new string, n int) string

替换字符串中的 old 为 new,n 为替换的最大次数(小于 0 表示全部替换)

func (StrType) Rtrim

func (st StrType) Rtrim(str, charsets string) string

将字符串右侧指定字符集合 charsets 中的字符去除

func (StrType) SortAndBinSearch

func (st StrType) SortAndBinSearch(value string, arr []string) int

对数组排序并进行二分查找法,成功返回查找到的数组下标,失败返回 -1

func (StrType) Split

func (st StrType) Split(str, sep string) []string

将字符串 str 照sep进行分割,并返回分割后的字符串数组,同 strings.Split()

func (StrType) Sub

func (st StrType) Sub(str string, begin, length int) string

utf8(6 bytes at most) substring

func (StrType) Trim

func (st StrType) Trim(str, charsets string) string

将字符串左右两侧指定字符集合 charsets 中的字符去除

func (StrType) TrimSpace

func (st StrType) TrimSpace(str string) string

将字符串首尾的空白字符去除

func (StrType) Uint

func (st StrType) Uint(str string, errValue uint) uint

Covert string to unsigned int using strconv.Atoi(), return errValue if err != nil or value < 0

func (StrType) UpperFirst

func (st StrType) UpperFirst(str string) string

将字符串首字母大写

type UintType

type UintType struct{}

func (UintType) ArrayAsc

func (ut UintType) ArrayAsc(arr []uint64)

数组排序 asc

func (UintType) ArrayDesc

func (ut UintType) ArrayDesc(arr []uint64)

数组排序 desc

func (UintType) Avg

func (ut UintType) Avg(values ...uint64) float64

Avg:计算 uint64 类型的值数组中所有值的平均值。

func (UintType) BinFind

func (ut UintType) BinFind(value uint64, arr []uint64, isAsc bool) int

二分查找数组

此函数适用于数组值已排序或将对同一数组进行多次查找,传入已排序的数组以提高效率。 注:若传入未排序的数组,结果可能并不符合预期。

成功时返回查找到的数组下标,失败返回 -1

func (UintType) BinSearch

func (ut UintType) BinSearch(value uint64, arr []uint64, isAsc bool) int

二分查找(此函数不会进行排序,请输入已排序的数组,否则会产生非预期结果) 成功返回查找到的数组下标,失败返回 -1

func (UintType) ConvertTo

func (ut UintType) ConvertTo(from uint64, toValue any) error

将 uint64 类型转换为 其他int 类型, 仅限int类型内转换

toValue 必须为 int相关类型的指针 eg.

var val int8
if err := ConvertTo(12, &val); err != nil {}

func (UintType) Find

func (ut UintType) Find(value uint64, arr []uint64) int

查找数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

二分查找时,将会对数组进行升序排序,查找成功返回的也会是升序后的下标

成功时返回查找到的数组下标,失败返回 -1

func (UintType) FindSorted

func (ut UintType) FindSorted(value uint64, arr []uint64, isAsc bool) int

查找已排序数组 如果数组长度超过规定值,使用二分查找,否则使用遍历查找

成功时返回查找到的数组下标,失败返回 -1

func (UintType) If

func (ut UintType) If(isTrue bool, trueValue, falseValue uint64) uint64

If 根据条件判断返回不同的值。

func (UintType) InArray

func (ut UintType) InArray(value uint64, arr []uint64) bool

整数切片查找,threshold 参数生效

func (UintType) InRange

func (ut UintType) InRange(value, min, max uint64) bool

实现判断指定的 uint64 类型值是否在指定的范围内的功能,返回布尔值

func (UintType) InSortedArray

func (ut UintType) InSortedArray(value uint64, arr []uint64, isAsc bool) bool

已排序数组查找,threshold 参数生效

func (UintType) IsEven

func (ut UintType) IsEven(value uint64) bool

实现判断指定的 uint64 类型值是否为偶数的功能,返回布尔值

func (UintType) IsOdd

func (ut UintType) IsOdd(value uint64) bool

实现判断指定的 uint64 类型值是否为奇数的功能,返回布尔值

func (UintType) LoopFind

func (ut UintType) LoopFind(value uint64, arr []uint64) int

遍历查找数组

如果数组长度较长或对同一数组做多次 LoopFind,建议先 ArrayAsc 后使用 BinFind

成功时返回查找到的数组下标,失败返回 -1

func (UintType) Max

func (ut UintType) Max(values ...uint64) uint64

Max:获取 uint64 类型的值数组中的最大值。

func (UintType) Min

func (ut UintType) Min(values ...uint64) uint64

Min:获取 uint64 类型的值数组中的最小值。

func (UintType) SortAndBinSearch

func (ut UintType) SortAndBinSearch(value uint64, arr []uint64) int

对数组排序(不会改变原数组顺序)并进行二分查找法,成功返回查找到的数组下标,失败返回 -1

func (UintType) Str

func (ut UintType) Str(value uint64) string

将 uint64 类型的数据转化为字符串类型

func (UintType) Sum

func (ut UintType) Sum(values ...uint64) uint64

Sum:计算 uint64 类型的值数组中所有值的总和。

Jump to

Keyboard shortcuts

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