stringx

package
v0.0.0-...-ee5f517 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2015 Huan Du. All rights reserved. Licensed under the MIT license that can be found in the LICENSE file. https://github.com/huandu/xstrings

  • @Author: qida

  • @LastEditors: qida

  • @Author: qida

  • @LastEditors: qida

Copyright 2015 Huan Du. All rights reserved. Licensed under the MIT license that can be found in the LICENSE file. https://github.com/huandu/xstrings

Index

Constants

View Source
const (
	Type未知 = 0
	Type数字 = 1
	Type手机 = 2
	Type字母 = 2
	Type汉字 = 3
	Type身份 = 4
)

Variables

View Source
var StateNames = [...]string{"⌛", "🟢", "🟡", "🔴"}

Functions

func AESGCMDecrypt

func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error)

AESGCMDecrypt decrypts ciphertext with the given key using AES in GCM mode.

func AESGCMEncrypt

func AESGCMEncrypt(key, plaintext []byte) ([]byte, error)

AESGCMEncrypt encrypts plaintext with the given key using AES in GCM mode.

func AmountConvert

func AmountConvert(p_money float64, p_Round bool) string

func ByteSliceToString

func ByteSliceToString(bytes []byte) string

*

  • 字节数组转字符串
  • @description
  • @param bytes要转换的数组
  • @return string *

func Camel2Case

func Camel2Case(name string) string

Camel2Case 驼峰式写法转为下划线写法

func CamelString

func CamelString(s string) string

*

  • 蛇形转驼峰
  • @description xx_yy to XxYx xx_y_y to XxYY
  • @param s要转换的字符串
  • @return string *

func Case2Camel

func Case2Camel(name string) string

Case2Camel 下划线写法转为驼峰写法

func DBCtoSBC

func DBCtoSBC(s string) string

全角转半角

func Expand

func Expand(template string, match map[string]string, subs ...string) string

Expand replaces {k} in template with match[k] or subs[atoi(k)] if k is not in match.

func FirstRuneToLower

func FirstRuneToLower(str string) string

FirstRuneToLower converts first rune to lower case if necessary.

func FirstRuneToUpper

func FirstRuneToUpper(str string) string

FirstRuneToUpper converts first rune to upper case if necessary.

func GetKeyWordType

func GetKeyWordType(key_word string) (type_word int8)

func GetKeysString

func GetKeysString(key_str string) (number int, py string, han string)

func IsLetter

func IsLetter(l uint8) bool

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

func Lcfirst

func Lcfirst(str string) string

Lcfirst 首字母小写

func NumReg

func NumReg(han string) int

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

func RandomCreateBytes

func RandomCreateBytes(n int, alphabets ...byte) []byte

RandomCreateBytes generate random []byte by specify chars.

func RemoveRepeatJoin

func RemoveRepeatJoin(src string, dst string) string

func Reverse

func Reverse(s string) string

Reverse s string, support unicode

func Show_substr

func Show_substr(s string, l int) string

func Shuffle

func Shuffle(str string) string

Shuffle randomizes runes in a string and returns the result. It uses default random source in `math/rand`.

func ShuffleSource

func ShuffleSource(str string, src rand.Source) string

ShuffleSource randomizes runes in a string with given random source.

func SnakeString

func SnakeString(s string) string

*

  • 驼峰转蛇形 snake string
  • @description XxYy to xx_yy , XxYY to xx_y_y
  • @param s 需要转换的字符串
  • @return string *

func StringToByteSlice

func StringToByteSlice(s string) []byte

*

  • 字符串转字节数组
  • @description
  • @param s要转换的字符串
  • @return string *

func Sub

func Sub(str string, start, length int) string

func SubString

func SubString(str string, begin, length int) (substr string)

func Substr

func Substr(str string, start int, length int) string

func Substr2

func Substr2(str string, start int, end int) string

*

*

func SubstrByByte

func SubstrByByte(str string, length int) string

按字节截取字符串 utf-8不乱码

func Successor

func Successor(str string) string

Successor returns the successor to string.

If there is one alphanumeric rune is found in string, increase the rune by 1. If increment generates a "carry", the rune to the left of it is incremented. This process repeats until there is no carry, adding an additional rune if necessary.

If there is no alphanumeric rune, the rightmost rune will be increased by 1 regardless whether the result is a valid rune or not.

Only following characters are alphanumeric.

  • a - z
  • A - Z
  • 0 - 9

Samples (borrowed from ruby's String#succ document):

"abcd"      => "abce"
"THX1138"   => "THX1139"
"<<koala>>" => "<<koalb>>"
"1999zzz"   => "2000aaa"
"ZZZ9999"   => "AAAA0000"
"***"       => "**+"

func SwapCase

func SwapCase(str string) string

SwapCase will swap characters case from upper to lower or lower to upper.

func ToCamelCase

func ToCamelCase(str string) string

ToCamelCase is to convert words separated by space, underscore and hyphen to camel case.

Some samples.

"some_words"      => "SomeWords"
"http_server"     => "HttpServer"
"no_https"        => "NoHttps"
"_complex__case_" => "_Complex_Case_"
"some words"      => "SomeWords"

func ToKebabCase

func ToKebabCase(str string) string

ToKebabCase can convert all upper case characters in a string to kebab case format.

Some samples.

"FirstName"    => "first-name"
"HTTPServer"   => "http-server"
"NoHTTPS"      => "no-https"
"GO_PATH"      => "go-path"
"GO PATH"      => "go-path"  // space is converted to '-'.
"GO-PATH"      => "go-path"  // hyphen is converted to '-'.
"http2xx"      => "http-2xx" // insert an underscore before a number and after an alphabet.
"HTTP20xOK"    => "http-20x-ok"
"Duration2m3s" => "duration-2m3s"
"Bld4Floor3rd" => "bld4-floor-3rd"

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase can convert all upper case characters in a string to snake case format.

Some samples.

"FirstName"    => "first_name"
"HTTPServer"   => "http_server"
"NoHTTPS"      => "no_https"
"GO_PATH"      => "go_path"
"GO PATH"      => "go_path"  // space is converted to underscore.
"GO-PATH"      => "go_path"  // hyphen is converted to underscore.
"http2xx"      => "http_2xx" // insert an underscore before a number and after an alphabet.
"HTTP20xOK"    => "http_20x_ok"
"Duration2m3s" => "duration_2m3s"
"Bld4Floor3rd" => "bld4_floor_3rd"

func Ucfirst

func Ucfirst(str string) string

Ucfirst 首字母大写

func UnicodeIndex

func UnicodeIndex(str, substr string) int

func VersionToInt

func VersionToInt(version string) int

versionToIntSlice 将版本号字符串转换为整数切片。

Types

type Buffer

type Buffer struct {
	*bytes.Buffer
}

Buffer 内嵌bytes.Buffer,支持连写

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(i interface{}) *Buffer

type JsonCamelCase

type JsonCamelCase struct {
	Value interface{}
}

************************************** 驼峰json **************************************

func (JsonCamelCase) MarshalJSON

func (c JsonCamelCase) MarshalJSON() ([]byte, error)

type JsonSnakeCase

type JsonSnakeCase struct {
	Value interface{}
}

************************************** 下划线json **************************************

func (JsonSnakeCase) MarshalJSON

func (c JsonSnakeCase) MarshalJSON() ([]byte, error)

type Range

type Range struct {
	Min int
	Max int
}

func (Range) MarshalJSON

func (t Range) MarshalJSON() ([]byte, error)

func (*Range) Scan

func (t *Range) Scan(v interface{}) (_err error)

func (*Range) UnmarshalJSON

func (t *Range) UnmarshalJSON(data []byte) (_err error)

func (Range) Value

func (t Range) Value() (driver.Value, error)

type Trie

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

A Trie is a tree implementation that used to find elements rapidly.

func NewTrie

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

NewTrie returns a Trie.

type TrieOption

type TrieOption func(trie *trieNode)

TrieOption defines the method to customize a Trie.

func WithMask

func WithMask(mask rune) TrieOption

WithMask customizes a Trie with keywords masked as given mask char.

Jump to

Keyboard shortcuts

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