zbutil

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: LGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const DateLayout = "2006-01-02"
View Source
const HoMSLayout = "15:04:05"
View Source
const InvalidCharInName = "@#$%&*()<>,;./?:\"'\\|+="
View Source
const TimeBase = "2012-01-01 00:00:00" //这天是星期天,世界末日后新的纪元开始
View Source
const TimeInvalid = "2011-12-31 23:59:59"
View Source
const TimeLayout = "2006-01-02 15:04:05"
View Source
const TimeLayoutM = "2006-01-02 15:04"
View Source
const TimeLayoutm = "2006-01-02 15:04:05.000"

Variables

View Source
var AsciiChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+,.?/:;{}[]`~")
View Source
var NotExist = &ErrNotExist{error: fmt.Errorf("Not Exist.")}
View Source
var NumChars = []byte("0123456789")

Functions

func AnyToInt32

func AnyToInt32(ipara any) int32

func AnyToString

func AnyToString(ipara any) string

func Atobool

func Atobool(s string) (bool, error)

func Atoi

func Atoi(s string) (int32, error)

func Atoi16

func Atoi16(s string) (int16, error)

func Atoi64

func Atoi64(s string) (int64, error)

func Atoiu

func Atoiu(s string) (uint32, error)

func Base64DecodeStr

func Base64DecodeStr(base64str string) []byte

base解码

func Base64EncodeStr

func Base64EncodeStr(bin []byte) string

base编码

func Between

func Between[T zbcmn.Ordered](my, start, end T) bool

func Bin2Str

func Bin2Str(bin []byte) string

func Bytes2Ints

func Bytes2Ints[T zbcmn.Integer](no_copy bool, bytes []byte) []T

func Bytes2Ints_

func Bytes2Ints_[T zbcmn.Integer](no_copy bool, bytes ...byte) []T

func Bytes2Str

func Bytes2Str(no_copy bool, bytes []byte) string

func BytesInt64

func BytesInt64(bytes []byte) int64

func CastPTR

func CastPTR(srcptr any, destype any) any

func CountFunc

func CountFunc(nlen int, cond func(i int) bool) int

CountFunc 计算符合条件的序列项总数

func DecryptDES_CBC

func DecryptDES_CBC(src, key []byte) ([]byte, error)

CBC解密

func DecryptDES_ECB

func DecryptDES_ECB(src, key []byte) ([]byte, error)

ECB解密

func DeepCopy

func DeepCopy(dst, src any) error

func DelMulti

func DelMulti[IDX zbcmn.Integer](nlen int, fassign func(i, j IDX), deletedidx ...IDX) (deletedcount int)

DelMulti 删除序列数据中多个下标的数据,调用方需自行缩短序列的长度去掉末尾的deletedcount个元素

func DelNotCond

func DelNotCond(nlen int, fassign func(i, j int), keepcond func(i int) bool, finish func(deletedcount int)) bool

DelNotCond 删除不符合条件的多个序列元素,调用方需在finish中去掉末尾的deletedcount个元素

func EncryptDES_CBC

func EncryptDES_CBC(src, key []byte) ([]byte, error)

CBC加密

func EncryptDES_ECB

func EncryptDES_ECB(src, key []byte) ([]byte, error)

ECB加密

func EscQuotes

func EscQuotes(str string, chars_esc string, 识别转义 bool) string

EscQuotes 数据库sql语句的字符串中单双引号转义,force_esc==true为理解上层的数据库转义,否则为不理解,原文本存入

func FetchIntArgInStr

func FetchIntArgInStr(str, prefix, sepchas string) (arg int, err error)

func Fn

func Fn[T any](tf T) func() T

func GetMonthZeroTime

func GetMonthZeroTime() uint32

GetMonthZeroTime 获取本月零点时间戳

func GetNextMonthZeroTime

func GetNextMonthZeroTime() uint32

GetNextMonthZeroTime 获取下月零点时间戳

func GetNextWeekZeroTime

func GetNextWeekZeroTime() uint32

GetNextWeekZeroTime 获取下周零点时间戳(下周一)

func GetNextWeekdayZeroTime

func GetNextWeekdayZeroTime(weekday uint32) uint32

GetNextWeekdayZeroTime 获取最近一个周几的零点时间戳(周日为7)

func GetPreMonthZeroTime

func GetPreMonthZeroTime() uint32

GetPreMonthZeroTime 获取上月零点时间戳

func GetPreWeekZeroTime

func GetPreWeekZeroTime() uint32

GetPreWeekZeroTime 获取上周零点时间戳(上周一)

func GetTick

func GetTick() int64

func GetTodayWeekday

func GetTodayWeekday() int32

GetTodayWeekday 获取当前星期数(周日为7)

func GetTodayZeroTime

func GetTodayZeroTime() uint32

GetTodayZeroTime 获取今天零点时间戳

func GetTomorrowZeroTime

func GetTomorrowZeroTime() uint32

GetTomorrowZeroTime 获取明天零点时间戳

func GetWeekZeroTime

func GetWeekZeroTime() uint32

GetWeekZeroTime 获取本周零点时间戳(周一)

func GetYesterdayZeroTime

func GetYesterdayZeroTime() uint32

GetYesterdayZeroTime 获取昨天零点时间戳

func I16toa

func I16toa(i int16) string

func I64toa

func I64toa(i int64) string

func IF

func IF[T any](cond bool, true_t T, false_t T) T

func IFF

func IFF[T any](cond bool, true_t func() T, false_t func() T) func() T

func IPv4itoa

func IPv4itoa(IPi uint32) string

func InSet

func InSet[T comparable](a T, set ...T) bool

InSet 是否在一个集合中

func Index

func Index[T comparable](arr []T, val T) int

Index 查找第一个索引

func IndexFunc

func IndexFunc(nlen int, cond func(i int) bool) int

IndexFunc 正向搜索符合条件的项目,返回第一个下标

func IndexLastFunc

func IndexLastFunc(nlen int, cond func(i int) bool) int

IndexFunc 反向搜索符合条件的项目,返回第一个下标

func IndexScope

func IndexScope[T zbcmn.Ordered](a []T, _Left, _Right T) (int, int)

IndexScope 返回已排序序列[]T中介于半闭包区间[_Left,_Right)的下标范围

func Int64Bytes

func Int64Bytes(i64 int64) []byte

=========================================

func Ints2Bytes

func Ints2Bytes[T zbcmn.Integer](no_copy bool, ints []T) []byte

func Ints2Bytes_

func Ints2Bytes_[T zbcmn.Integer](no_copy bool, ints ...T) []byte

func Itoa

func Itoa(i int32) string

func Iutoa

func Iutoa(i uint32) string

func LenChaInStr

func LenChaInStr(str string, idx int) (chalen int)

func Lowerbound

func Lowerbound(nlen int, fmore_eq func(i int) bool) int

Lowerbound 二分查找,复杂度O(n)=log2_n 返回>={搜索值}的最小索引,fmore_eq:=func(i int)bool{return arr[i]>={搜索值}}

func MakeUnique

func MakeUnique(nlen int, less func(i, j int) bool, swap func(i, j int), equal func(i, j int) bool, assign func(i, j int)) (deletedcount int)

MakeUnique 算法工具函数 使 序列数据 去重复

func MakeUnique2

func MakeUnique2(nlen int, less func(i, j int) bool, swap func(i, j int)) (deletedcount int)

MakeUnique2 简化版的MakeUnique 使 序列数据 去重复

func MakeUniqueType

func MakeUniqueType[T zbcmn.Ordered](arr ...T) []T

MakeUniqueType 使内置可排序类型 序列数据 去重复

func Max

func Max[T zbcmn.Ordered](i1, i2 T) T

func Md5Bin

func Md5Bin(src []byte) []byte

md5验证

func Md5Str

func Md5Str(src string) string

md5验证

func Min

func Min[T zbcmn.Ordered](i1, i2 T) T

func NewLenRandomChars

func NewLenRandomChars(length int, chars []byte) string

func NextChaInStr

func NextChaInStr(str string, idx int) (nextcidx int)

func Now

func Now() uint32

func Now64

func Now64() int64

func NowStr

func NowStr() string

func NowStr64

func NowStr64() string

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

明文补码

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

明文减码

func Parallel

func Parallel(n_ms, n_len, ntimes int, run func(idx int) bool) (retidx int)

Parallel 并行限时运行,返回最先run(idx)为true的索引 n_ms 毫秒数,没有找到或查找超时,retidx返回-1 ntimes 子routine run()多少次检查一次break,根据run()的重度程度决定,轻度run一般设置10-100,重度run设置1-10

func Randn

func Randn(n uint64) uint64

Randn 获取cpu硬件随机数

func ReplaceAny

func ReplaceAny(s, old_asciis string, new_ascii byte) string

RelaceAny从s中搜索任意一个old_asciis中的每一个ascii码字符,搜索到了使用new_ascii进行替换

func Reverse

func Reverse(nlen int, fswap func(i, j int))

Reverse 颠倒存储序列内容

func RsaDecrypt

func RsaDecrypt(ciphertext []byte, privateKey []byte) ([]byte, error)

解密

func RsaEncrypt

func RsaEncrypt(origData []byte, publicKey []byte) ([]byte, error)

加密

func RsaSign

func RsaSign(signedtxt []byte, privateKey []byte) ([]byte, error)

签名

func RsaVerify

func RsaVerify(signedtxt, signdata []byte, publicKey []byte) error

验证签名

func Sha256Bin

func Sha256Bin(src []byte) []byte

sha256指纹

func Sha256Str

func Sha256Str(src string) string

sha256指纹

func Sha512Bin

func Sha512Bin(src []byte) []byte

sha512指纹

func Sha512Str

func Sha512Str(src string) string

sha512指纹

func Sort

func Sort(nlen int, fless func(i, j int) bool, fswap func(i, j int))

Sort 使用快速排序算法排序序列

func SortArr

func SortArr[A zbcmn.Ordered](a ...A) []A

SortArr 使用快速排序算法排序内建可排序类型的序列

func SplitByBrace

func SplitByBrace(str, left_right_brace string) [3]string

返回值:left, in_brace, right

func SplitFields

func SplitFields(s string, sepchas string, or_space bool) []string

func SplitInt16s

func SplitInt16s(s string, sepchas string, or_space bool) (retval []int16, reterr error)

func SplitInt64s

func SplitInt64s(s string, sepchas string, or_space bool) (retval []int64, reterr error)

func SplitInts

func SplitInts(s string, sepchas string, or_space bool) (retval []int32, reterr error)

func SplitUInt64s

func SplitUInt64s(s string, sepchas string, or_space bool) (retval []uint64, reterr error)

func Str2Bin

func Str2Bin(str string) ([]byte, error)

func Str2Bytes

func Str2Bytes(no_copy bool, s string) []byte

func TimeAbs2Rel

func TimeAbs2Rel(tm time.Time) uint32

TimeAbs2Rel 绝对时间到相对时间

func TimeAbs2Rel64

func TimeAbs2Rel64(tm time.Time) int64

TimeAbs2Rel64 绝对时间到相对时间

func TimeAbs2Str

func TimeAbs2Str(abs time.Time) string

func TimeAbs2Str64

func TimeAbs2Str64(abs time.Time) string

func TimeArrive

func TimeArrive(currtick int64, valuetick int64) bool

func TimeExceed

func TimeExceed(currtick int64, valuetick int64) bool

func TimeGetInv

func TimeGetInv() time.Time

TimeGetInv 获得统一的无效时间常量

func TimeIsValid

func TimeIsValid(time time.Time) bool

TimeIsValid 判断时间是不是统一的无效时间

func TimeRel2Abs

func TimeRel2Abs(rela uint32) time.Time

TimeRel2Abs 相对时间到绝对时间

func TimeRel2Abs64

func TimeRel2Abs64(rela int64) time.Time

TimeRel2Abs64 相对时间到绝对时间

func TimeRel2Str

func TimeRel2Str(rela uint32) string

func TimeRel2Str64

func TimeRel2Str64(rela int64) string

func TimeStr2Rel

func TimeStr2Rel(tm string) uint32

func TimedIndex

func TimedIndex[T comparable](n_ms int, arr []T, at T) (retidx int)

TimedIndex 并发限时查找,返回最先查找到的元素的索引 n_ms 毫秒数,没有找到或查找超时,返回-1

func TraverseFunc

func TraverseFunc(nlen int, skip func(i int) int)

TraverseFunc 跳跃遍历

func UnsafeAtoi

func UnsafeAtoi(s string) int32

func UnsafeAtoi64

func UnsafeAtoi64(s string) int64

func Upperbound

func Upperbound(neln int, fmore func(j int) bool) int

Upperbound 二分查找,复杂度O(n)=log2_n 返回>{搜索值}的最小索引,fmore:=func(i int)bool{return arr[i]>{搜索值}}

func ValidName

func ValidName(name string, maxlen int) bool

func ValidStr

func ValidStr(str string, maxlen int, 允许空格 bool) bool

func VerifyCHNcard

func VerifyCHNcard(cardno string) bool

Types

type Bitwise

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

Bitwise 按bit操作的大数结构

func NewBitwise

func NewBitwise(nsize int) *Bitwise

NewBitwise 分配一个新的Maskflag

func (*Bitwise) Bitlen

func (t *Bitwise) Bitlen() int

Bitlen 获取本maskflag的位长度

func (*Bitwise) Bitnot

func (t *Bitwise) Bitnot(idx int) bool

Reset 把idx位取反,1变0,0变1

func (*Bitwise) Bitwise

func (t *Bitwise) Bitwise(nsize int) *Bitwise

Bitwise 构造函数

func (*Bitwise) Fill

func (t *Bitwise) Fill(index int, val uint64) bool

Fill 填充第index个uint64为新值

func (*Bitwise) FromBytes

func (t *Bitwise) FromBytes(bs []byte, bitlen int) bool

FromBytes 从byte序列填充

func (*Bitwise) GetIndexVal

func (t *Bitwise) GetIndexVal(idx int) (index int, val uint64)

GetIndexVal 获取idx位所在的uint64索引index和uint64值

func (*Bitwise) IsMarked

func (t *Bitwise) IsMarked(idx int) bool

IsMarked 判断idx位是否为1

func (*Bitwise) Mark

func (t *Bitwise) Mark(idx int) bool

Mark 把idx位设置为1

func (*Bitwise) MarkAll

func (t *Bitwise) MarkAll()

MarkAll 全部bit都设置为1

func (*Bitwise) Reset

func (t *Bitwise) Reset(idx int) bool

Reset 把idx位设置0

func (*Bitwise) ResetAll

func (t *Bitwise) ResetAll()

ResetAll 全部bit都设置为0

func (*Bitwise) ToBytes

func (t *Bitwise) ToBytes() []byte

ToBytes 提取数据到byte序列

func (*Bitwise) ToInt32s

func (t *Bitwise) ToInt32s() []uint32

ToInt32s 转换为uint32序列

func (*Bitwise) UnsafeToBytes

func (t *Bitwise) UnsafeToBytes() []byte

UnsafeToBytes 不安全的连续内存强转byte序列

type BytesReader

type BytesReader []byte

func (*BytesReader) Read

func (r *BytesReader) Read(b []byte) (n int, err error)

type ErrNotExist

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

搜索str中prefix开头,sepchas结尾或到末尾的子串,子串转换为整数

type Rand

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

A Rand is a source of random numbers.

func NewRand

func NewRand(src Source) *Rand

func (*Rand) Float32

func (r *Rand) Float32() float32

func (*Rand) Float64

func (r *Rand) Float64() float64

func (*Rand) Int

func (r *Rand) Int() int

func (*Rand) Int31

func (r *Rand) Int31() int32

func (*Rand) Int31n

func (r *Rand) Int31n(n int32) int32

func (*Rand) Int63

func (r *Rand) Int63() int64

func (*Rand) Int63n

func (r *Rand) Int63n(n int64) int64

func (*Rand) Intn

func (r *Rand) Intn(n int) int

func (*Rand) Perm

func (r *Rand) Perm(n int) []int

func (*Rand) Read

func (r *Rand) Read(p []byte) (n int, err error)

func (*Rand) Seed

func (r *Rand) Seed(seed int64)

func (*Rand) Shuffle

func (r *Rand) Shuffle(n int, swap func(i, j int))

func (*Rand) Uint32

func (r *Rand) Uint32() uint32

func (*Rand) Uint64

func (r *Rand) Uint64() uint64

type SQLMgr

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

func (*SQLMgr) GetDBC

func (this *SQLMgr) GetDBC() *sql.DB

func (*SQLMgr) GetDBase

func (this *SQLMgr) GetDBase() string

func (*SQLMgr) GetIP

func (this *SQLMgr) GetIP() string

func (*SQLMgr) GetPasswd

func (this *SQLMgr) GetPasswd() string

func (*SQLMgr) GetPort

func (this *SQLMgr) GetPort() uint16

func (*SQLMgr) GetUsrName

func (this *SQLMgr) GetUsrName() string

func (*SQLMgr) SQLMgr

func (this *SQLMgr) SQLMgr(dbcmax, idlemax int, usrname, passwd, db, ip string, port uint16) *SQLMgr

type Source

type Source interface{ rand.Source }

A Source represents a source of uniformly-distributed pseudo-random int64 values in the range [0, 1<<63).

func NewSource

func NewSource(seed int64) Source

type Source64

type Source64 interface{ rand.Source64 }

A Source64 is a Source that can also generate uniformly-distributed pseudo-random uint64 values in the range [0, 1<<64) directly. If a Rand r's underlying Source s implements Source64, then r.Uint64 returns the result of one call to s.Uint64 instead of making two calls to s.Int63.

type StrBuilder

type StrBuilder struct{ strings.Builder }

func NewBuilder

func NewBuilder(buf []byte) (ret *StrBuilder)

func NewBuilderString

func NewBuilderString(s string) (ret *StrBuilder)

Jump to

Keyboard shortcuts

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