bytesKit

package
v3.0.94 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Compare func(a, b []byte) int = bytes.Compare

Compare 按照字典序比较两个字节切片的大小.

@param a 可以为nil @param b 可以为nil @return -1: a < b

0:	a == b
1:	a > b
View Source
var Contains func(b, subslice []byte) bool = bytes.Contains

Contains 判断 subslice 子字节切片是否包含在 b 字节切片

View Source
var Count func(s, sep []byte) int = bytes.Count

Count 统计 sep 字节切片在 s 字节切片中非重叠实例数

View Source
var HasPrefix func(s, prefix []byte) bool = bytes.HasPrefix

HasPrefix 字节切片 s 是否以 prefix 开头

View Source
var HasSuffix func(s, suffix []byte) bool = bytes.HasSuffix

HasSuffix 字节切片 s 是否以 suffix 结尾

View Source
var Index func(s, sep []byte) int = bytes.Index

Index 查找 sep 在 s 中第一次出现的索引下标,如果没有则返回 -1

View Source
var LastIndex func(s, sep []byte) int = bytes.LastIndex

LastIndex 查找 sep 在 s 中最后一次出现的索引下标,如果没有则返回 -1

View Source
var Split func(s, sep []byte) [][]byte = bytes.Split

Split 将 sep 作为分割符,将 s 分割,返回拆分之后的字节切片

View Source
var SplitN func(s, sep []byte, n int) [][]byte = bytes.SplitN

SplitN 将 sep 作为分割符,将 s 分割 n 份,返回拆分之后的字节切片

View Source
var ToLower func(s []byte) []byte = bytes.ToLower

ToLower 将字节切片所有字节全部转换为小写字母,返回该字节切片的一个副本

View Source
var ToUpper func(s []byte) []byte = bytes.ToUpper

ToUpper 将字节切片所有字节全部转换为大小字母,返回该字节切片的一个副本

View Source
var Trim func(s []byte, cutset string) []byte = bytes.Trim

Trim 返回清除 s 中开头和结尾存在的 cutset 之后的一个子切片

View Source
var TrimLeft func(s []byte, cutset string) []byte = bytes.TrimLeft

TrimLeft 返回清除 s 中开头存在的 cutset 之后的一个子切片

View Source
var TrimRight func(s []byte, cutset string) []byte = bytes.TrimRight

TrimRight 返回清除 s 中结尾存在的 cutset 之后的一个子切片

View Source
var TrimSpace func(s []byte) []byte = bytes.TrimSpace

TrimSpace 返回清除 s 中开头和结尾存在的 \t\n\r 之后的一个子切片

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString []byte => string

Go 如何让在强制转换类型时不发生内存拷贝

https://mp.weixin.qq.com/s/wvJm0Q95PTB_YUkZq51C8Q

PS: (1) 参考了 gin(v1.9.1) 中的 internal/bytesconv/bytesconv.go ,后续要及时同步更新此方法! (2) 必须满足的条件:对数据仅仅只有读操作!!!

func Equals

func Equals(a, b []byte) bool

Equals

PS: 两个传参都为nil,将返回true.

@param a 可以为nil @param b 可以为nil

e.g.

var a = []byte("abcd")
var b = []byte("abcd")
println(bytesKit.Equals(a, b)) // true
b = []byte("abcd1")
println(bytesKit.Equals(a, b))     // false
println(bytesKit.Equals(a, nil))   // false
println(bytesKit.Equals(nil, nil)) // true

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes string => []byte

Go 如何让在强制转换类型时不发生内存拷贝

https://mp.weixin.qq.com/s/wvJm0Q95PTB_YUkZq51C8Q

PS: (1) 参考了 gin(v1.9.1) 中的 internal/bytesconv/bytesconv.go ,后续要及时同步更新此方法! (2) 必须满足的条件:对数据仅仅只有读操作!!!

Types

This section is empty.

Jump to

Keyboard shortcuts

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