stringex

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Example
SetClipboard("ab")
text := GetClipboard()
fmt.Println(text)
Output:

ab

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	LowerAlpha = []rune("abcdefghijklmnopqrstuvwxyz")
	UpperAlpha = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
	Digits     = []rune("0123456789")
	Letter     = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
	AllLetter  = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
)

Functions

func AppendStr

func AppendStr(strs []string, str string) []string

AppendStr appends string to slice with no duplicates.

func ArrayChunk

func ArrayChunk(array interface{}, size int) []interface{}

ArrayChunk split an array into chunks

func Base58Decode added in v0.1.1

func Base58Decode(input []byte) []byte

Base58Decode decodes Base58-encoded data

func Base58Encode added in v0.1.1

func Base58Encode(input []byte) []byte

Base58Encode 将二进制数组编译成base58

func ByteToHex

func ByteToHex(data []byte) string

ByteToHex byte转16进制字符串

func ByteToString added in v0.1.1

func ByteToString(b []byte) string

BytesToString convert []byte type to string type.

func CompareSliceStr

func CompareSliceStr(s1, s2 []string) bool

CompareSliceStr compares two 'string' type slices. It returns true if elements and order are both the same.

func CompareSliceStrU

func CompareSliceStrU(s1, s2 []string) bool

CompareSliceStrU compares two 'string' type slices. It returns true if elements are the same, and ignores the order.

func ConcatString

func ConcatString(s ...string) string

ConcatString 连接字符串 NOTE: 性能比fmt.Sprintf和+号要好

func ConvertString

func ConvertString(src string, tagCode string) string

ConvertString 系统转其他

func ConvertToByte

func ConvertToByte(key interface{}) ([]byte, error)

GetBytes interface 转 byte

func ConvertToFloat64

func ConvertToFloat64(unk interface{}) (float64, error)

func ConvertToString

func ConvertToString(value interface{}) (string, error)

func DbcToSbc

func DbcToSbc(str string) string

DbcToSbc 全角转半角

func DecodeByte

func DecodeByte(data []byte, to interface{}) error

DecodeByte 解码二进制

func DeleteValueByIndex added in v0.1.1

func DeleteValueByIndex(obj []interface{}, idx int) []interface{}

* DeleteValueByIndex 删除slice中的元素

func EncodeByte

func EncodeByte(data interface{}) ([]byte, error)

EncodeByte 编码二进制

func ExpandTabs

func ExpandTabs(str string, count int) string

ExpandTabs converts tabs to the spaces. count specifies the number of spaces

Example
fmt.Printf("%s", ExpandTabs("\tlorem\n\tipsum", 2))
Output:

  lorem
  ipsum

func FilterEmptyString added in v0.0.8

func FilterEmptyString(in []string) (out []string)

func GenerateV1

func GenerateV1() string

Generate 标准的UUID风格算法 based on timestamp and MAC address (RFC 4122)

func GenerateV4

func GenerateV4() string

Generate 标准的UUID风格算法 based on random numbers (RFC 4122)

func GetClipboard

func GetClipboard() string

Get 读取剪切板中的内容到字符串

func GetFuncName

func GetFuncName(f interface{}) string

GetFuncName 获取函数名

func GetGBK

func GetGBK(src string) string

GetGBK 获取gbk

func HexStr2int

func HexStr2int(hexStr string) (int, error)

HexStr2int converts hex format string to decimal number.

func HexToBye

func HexToBye(hexStr string) []byte

HexToBye 16进制字符串转[]byte

func InArray

func InArray(needle interface{}, haystack interface{}) bool

InArray checks if a value exists in an array

func IncludesString

func IncludesString(texts []string, text string) bool

func Indent

func Indent(str string, left string) string

Indent indents every line of string str with the left parameter Empty lines are indented too.

Example
fmt.Println(Indent("Lorem ipsum\ndolor sit amet", " > "))
Output:

 > Lorem ipsum
 > dolor sit amet

func Int2HexStr

func Int2HexStr(num int) (hex string)

Int2HexStr converts decimal number to hex format string.

func Interface2Int added in v0.0.8

func Interface2Int(value interface{}) (int, error)

Interface2Int interface{} 转换成数字

func Interface2String added in v0.0.8

func Interface2String(value interface{}) string

Interface2String 对象转字符串

func InterfaceIsEmpty added in v0.0.8

func InterfaceIsEmpty(value interface{}) bool

InterfaceIsEmpty 是否是空

func IsAlpha added in v0.1.1

func IsAlpha(s string) bool

IsAlpha checks if the string contains only unicode letters.

func IsAlphanumeric added in v0.1.1

func IsAlphanumeric(s string) bool

IsAlphanumeric checks if the string contains only Unicode letters or digits.

func IsChineseChar added in v0.0.7

func IsChineseChar(str string) bool

IsChineseChar 是否为中文

func IsContains added in v0.1.1

func IsContains(item string, sl []string) bool

* IsContains 元素是否包含

func IsContainsInterface added in v0.1.1

func IsContainsInterface(item interface{}, sl []interface{}) bool

* IsContainsInterface 元素是否包含(interface)

func IsEmail added in v0.0.2

func IsEmail(email string) bool

func IsEmailRFC added in v0.0.2

func IsEmailRFC(email string) bool

func IsEmpty

func IsEmpty(value interface{}) bool

func IsIDCard added in v0.0.2

func IsIDCard(cardNo string) bool

IsIDCard 判断是否是18或15位身份证

func IsInSlice

func IsInSlice(value interface{}, sli interface{}) bool

IsInSlice 判断某一值是否在slice中 因为使用了反射,所以时间开销比较大,使用中根据实际情况进行选择

func IsInternalType added in v0.0.2

func IsInternalType(t string) bool

IsInternalType 是否是内部类型

func IsKeywords added in v0.0.2

func IsKeywords(t string) bool

IsKeywords 是否是关键字

func IsLetter

func IsLetter(l uint8) bool

IsLetter returns true if the 'l' is an English letter.

func IsNil

func IsNil(vi interface{}) (result bool)

func IsNumeric added in v0.1.1

func IsNumeric(s string) bool

IsNumeric Checks if the string contains only digits. A decimal point is not a digit and returns false.

func IsPhone added in v0.0.2

func IsPhone(mobileNum string) bool

IsPhone 判断是否是手机号

func IsRunTesting added in v0.0.2

func IsRunTesting() bool

IsRunTesting 判断是否在测试环境下使用

func IsSubset

func IsSubset(parent []interface{}, sub []interface{}) bool

IsSubset return true if the @sub is a subset of the @parent

func IsUrl added in v0.0.2

func IsUrl(url string) bool

func IsZero

func IsZero(i ...interface{}) bool

IsZero 检查是否是零值

func JoinInt

func JoinInt(is []int64) string

JoinInt format int64 slice to string, eg: n1,n2,n3.

func Lcfirst added in v0.0.7

func Lcfirst(str string) string

首字母小写

func LongestPalindromic added in v0.1.1

func LongestPalindromic(input string) string

func MapLines

func MapLines(str string, fn func(string) string) string
Example
fmt.Println(MapLines("Lorem\\nIpsum", strings.ToUpper))
Output:

LOREM
IPSUM

func Merge

func Merge(s1 []string, s2 []string) []string

func MinimumString

func MinimumString(rest []string) string

MinimumString 查找字符串最小值

func NewShortUUID added in v0.0.8

func NewShortUUID() string

func Next added in v0.0.9

func Next(tableIdx int64) int64

Next generate a distributed Primary Key tableIdx - table sharding index

func Random

func Random(n int, validRunes []rune) string

func RandomString

func RandomString(n int) string

func RegexpReplace

func RegexpReplace(reg, src, temp string) string

func RemoveChar added in v0.1.1

func RemoveChar(s string, rmVal rune) string

RemoveChar removes all occurrences of a specified character from the string.

func RemoveSliceString added in v0.1.1

func RemoveSliceString(texts []string, text string) []string

func RemoveString

func RemoveString(s, rmStr string) string

RemoveString removes all occurrences of a substring from the string.

func ReverseArray

func ReverseArray(a []int)

func ReverseBytes added in v0.0.5

func ReverseBytes(b []byte)

func ReverseSlice

func ReverseSlice(slice []interface{}) []interface{}

func ReverseString

func ReverseString(s string) string

Reverse s string, support unicode

func RuneWidth

func RuneWidth(r rune) int

func SetClipboard

func SetClipboard(cb string)

Set 复制内容到剪切板

func Slice

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

no copy to change string to slice use your own risk

func SliceContains

func SliceContains(arr []interface{}, elem interface{}) bool

SliceContains return true if the elem is in the array arr

func SliceContainsInt64

func SliceContainsInt64(sl []int64, i int64) bool

SliceContainsInt64 returns true if the int64 exists in given slice.

func SliceContainsStr

func SliceContainsStr(sl []string, str string) bool

SliceContainsStr returns true if the string exists in given slice, ignore case.

func SliceContainsUint

func SliceContainsUint(arr []uint, e uint) bool

func SliceContainsUint32

func SliceContainsUint32(arr []uint32, e uint32) bool

func SliceNotExistsUint32

func SliceNotExistsUint32(currentArr []uint32, oldArr []uint32) []uint32

func SliceShuffle

func SliceShuffle(slice []interface{})

SliceShuffle shuffle a slice

func SnakeString added in v0.1.1

func SnakeString(s string) string

SnakeString converts the accepted string to a snake string (XxYy to xx_yy)

func Sonyflake

func Sonyflake() string

Sonyflake 基于雪花算法生成

func SplitAndMap

func SplitAndMap(str string, split string, fn func(string) string) string

func SplitInt

func SplitInt(s string) ([]int64, error)

SplitInt split string into int64 slice.

func String

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

no copy to change slice to string use your own risk

func StringLength

func StringLength(str string) int

StringLength returns str utf8 rune length.

func StringSliceContains

func StringSliceContains(ss []string, s string) bool

StringSliceContains 字符串切片中是否包含另一个字符串 来自go源码 net/http/server.go

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual 判断 string和slice 是否相等 使用了传统的遍历方式

func StringSliceReflectEqual

func StringSliceReflectEqual(a, b []string) bool

StringSliceReflectEqual 判断 string和slice 是否相等 因为使用了反射,所以效率较低,可以看benchmark结果

func StringToBytes

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

StringToBytes convert string type to []byte type. NOTE: panic if modify the member value of the []byte.

func StringToInt

func StringToInt(str string) (int, error)

StringToInt 字符串转int

func StringToInt64

func StringToInt64(str string) (int64, error)

StringToInt64 字符串转int64

func StringToUint64

func StringToUint64(str string) (uint64, error)

StringToUint64 字符串转uint64

func SubString added in v0.1.1

func SubString(str string, start, length int) string
Example
fmt.Println(SubString("hello", 1, 2))
fmt.Println(SubString("hello", 1, 0))
Output:

el

func TableIdx added in v0.0.9

func TableIdx(id int64) int

TableIdx get the table index from id Give a ID return idx of table shard

func TranslateString

func TranslateString(src string, srcCode string, tagCode string) string

ConvertToString 字符集转换

func Ucfirst added in v0.0.7

func Ucfirst(str string) string

首字母大写

func Uint64DeleteElemInSlice

func Uint64DeleteElemInSlice(i int, s []uint64) []uint64

Uint64DeleteElemInSlice 从slice删除元素 fast version, 会改变顺序 i:slice的索引值 s: slice

func Uint64DeleteElemInSliceWithOrder

func Uint64DeleteElemInSliceWithOrder(i int, s []uint64) []uint64

Uint64DeleteElemInSliceWithOrder 从slice删除元素 slow version, 保持原有顺序 i:slice的索引值 s: slice

func Uint64ShuffleSlice

func Uint64ShuffleSlice(a []uint64) []uint64

Uint64ShuffleSlice 对slice进行随机

func Uint64SliceReverse

func Uint64SliceReverse(a []uint64) []uint64

Uint64SliceReverse 对uint64 slice 反转

func UnicodeEmojiCode

func UnicodeEmojiCode(s string) string

UnicodeEmojiCode Emoji表情转换

func UnicodeEmojiDecode

func UnicodeEmojiDecode(s string) string

UnicodeEmojiDecode Emoji表情解码

func UniqueString

func UniqueString(texts []string) []string

func Width

func Width(str string) int

func WordCount

func WordCount(str string) int

func Xid

func Xid() string

Xid 基于支持分布式算法:4 bytes time + 3 bytes machine id + 2 bytes process id + 3 bytes random

Types

type Arena

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

func NewArena

func NewArena(size int) *Arena

func (*Arena) Make

func (a *Arena) Make(size int) []byte

func (*Arena) Reset

func (a *Arena) Reset()

type Error

type Error struct {
	Value interface{}
	Type  string
}

func (Error) Error

func (c Error) Error() string

type Sequence added in v0.0.9

type Sequence struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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