gstr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotFoundIndex is the position index for string not found in searching functions.
	NotFoundIndex = -1
)

Variables

This section is empty.

Functions

func ChunkSplit added in v0.0.6

func ChunkSplit(body string, chunkLen int, end string) string

ChunkSplit splits a string into smaller chunks. Can be used to split a string into smaller chunks which is useful for e.g. converting BASE64 string output to match RFC 2045 semantics. It inserts end every chunkLen characters. It considers parameter `body` and `end` as unicode string.

func ClearWordRankCache added in v0.0.3

func ClearWordRankCache()

ClearWordRankCache 清除 WordRank 函数的缓存

func Explode added in v0.0.6

func Explode(delimiter, str string) []string

Explode splits string `str` by a string `delimiter`, to an array. See http://php.net/manual/en/function.explode.php.

func ExtractRegexMatch added in v0.0.3

func ExtractRegexMatch(regex, content string, index int) (string, error)

ExtractRegexMatch 提取正则表达式匹配的指定捕获组 参数:

  • regex: 正则表达式字符串
  • content: 要匹配的内容
  • index: 捕获组索引

返回值:匹配的字符串和可能的错误

func Fields added in v0.0.6

func Fields(str string) []string

Fields returns the words used in a string as slice.

func FirstToLower added in v0.0.3

func FirstToLower(str string) string

FirstToLower 将字符串的首字母转为小写 参数:

  • str: 输入字符串

返回值:首字母小写的字符串

func FirstToUpper added in v0.0.3

func FirstToUpper(str string) string

FirstToUpper 将字符串的首字母转为大写 参数:

  • str: 输入字符串

返回值:首字母大写的字符串

func GetRootDomain added in v0.0.3

func GetRootDomain(url string) string

GetRootDomain 获取根域名 参数:

  • url: 完整的URL或域名字符串

返回值:提取的根域名

func HasPrefix added in v0.0.7

func HasPrefix(s, prefix string) bool

HasPrefix 测试字符串 s 是否以 prefix 开头

func HasSuffix added in v0.0.7

func HasSuffix(s, suffix string) bool

HasSuffix 测试字符串 s 是否以 suffix 结尾

func HumpName added in v0.0.3

func HumpName(name string) string

HumpName 将下划线命名转换为驼峰命名 参数:

  • name: 下划线命名的字符串

返回值:驼峰命名的字符串

func Implode added in v0.0.6

func Implode(glue string, pieces []string) string

Implode joins array elements `pieces` with a string `glue`. http://php.net/manual/en/function.implode.php

func InStringArray added in v0.0.3

func InStringArray(needle string, haystack []string) bool

InStringArray 检查字符串是否在切片中 参数:

  • needle: 要查找的字符串
  • haystack: 字符串切片

返回值:如果找到返回true,否则返回false

func IsFloat added in v0.0.3

func IsFloat(s string) bool

IsFloat 判断字符串是否为浮点数 参数:

  • s: 要判断的字符串

返回值:如果是浮点数返回true,否则返回false

func IsInt added in v0.0.3

func IsInt(s string) bool

IsInt 判断字符串是否为整数 参数:

  • s: 要判断的字符串

返回值:如果是整数返回true,否则返回false

func IsSubDomain added in v0.0.6

func IsSubDomain(subDomain, mainDomain string) bool

IsSubDomain 检查 subDomain 是否为 mainDomain 的子域名。 支持在 mainDomain 中使用 '*' 通配符。

func Join added in v0.0.6

func Join(array []string, sep string) string

Join concatenates the elements of `array` to create a single string. The separator string `sep` is placed between elements in the resulting string.

func JoinAny added in v0.0.6

func JoinAny(array interface{}, sep string) string

JoinAny concatenates the elements of `array` to create a single string. The separator string `sep` is placed between elements in the resulting string.

The parameter `array` can be any type of slice, which be converted to string array.

func Pos

func Pos(haystack, needle string, startOffset ...int) int

Pos returns the position of the first occurrence of `needle` in `haystack` from `startOffset`, case-sensitively. It returns -1, if not found.

func PosI

func PosI(haystack, needle string, startOffset ...int) int

PosI returns the position of the first occurrence of `needle` in `haystack` from `startOffset`, case-insensitively. It returns -1, if not found.

func PosIRune

func PosIRune(haystack, needle string, startOffset ...int) int

PosIRune acts like function PosI but considers `haystack` and `needle` as unicode string.

func PosR

func PosR(haystack, needle string, startOffset ...int) int

PosR returns the position of the last occurrence of `needle` in `haystack` from `startOffset`, case-sensitively. It returns -1, if not found.

func PosRI

func PosRI(haystack, needle string, startOffset ...int) int

PosRI returns the position of the last occurrence of `needle` in `haystack` from `startOffset`, case-insensitively. It returns -1, if not found.

func PosRIRune

func PosRIRune(haystack, needle string, startOffset ...int) int

PosRIRune acts like function PosRI but considers `haystack` and `needle` as unicode string.

func PosRRune

func PosRRune(haystack, needle string, startOffset ...int) int

PosRRune acts like function PosR but considers `haystack` and `needle` as unicode string.

func PosRune

func PosRune(haystack, needle string, startOffset ...int) int

PosRune acts like function Pos but considers `haystack` and `needle` as unicode string.

func QuoteMeta

func QuoteMeta(str string, chars ...string) string

QuoteMeta returns a version of `str` with a backslash character (`\`). If custom chars `chars` not given, it uses default chars: .\+*?[^]($)

func Replace

func Replace(origin, search, replace string, count ...int) string

Replace returns a copy of the string `origin` in which string `search` replaced by `replace` case-sensitively.

func ReplaceByArray

func ReplaceByArray(origin string, array []string) string

ReplaceByArray returns a copy of `origin`, which is replaced by a slice in order, case-sensitively.

func ReplaceByMap

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-sensitively.

func ReplaceI

func ReplaceI(origin, search, replace string, count ...int) string

ReplaceI returns a copy of the string `origin` in which string `search` replaced by `replace` case-insensitively.

func ReplaceIByArray

func ReplaceIByArray(origin string, array []string) string

ReplaceIByArray returns a copy of `origin`, which is replaced by a slice in order, case-insensitively.

func ReplaceIByMap

func ReplaceIByMap(origin string, replaces map[string]string) string

ReplaceIByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-insensitively.

func ReplaceIndex added in v0.0.3

func ReplaceIndex(s, old, new string, n int) string

ReplaceIndex 替换字符串中第n次出现的旧字符串 参数:

  • s: 原字符串
  • old: 要替换的旧字符串
  • new: 新字符串
  • n: 第几次出现(从0开始)

返回值:替换后的字符串

func ReplaceRegexMatch added in v0.0.3

func ReplaceRegexMatch(regex, newStr, content string) (string, error)

ReplaceRegexMatch 使用新字符串替换所有正则表达式匹配项 参数:

  • regex: 正则表达式字符串
  • newStr: 用于替换的新字符串
  • content: 要处理的内容

返回值:替换后的字符串和可能的错误

func ResolveAddress added in v0.0.3

func ResolveAddress(addr []string) (string, error)

ResolveAddress 解析地址 参数:

  • addr: 地址参数切片

返回值:解析后的地址字符串和可能的错误

func SetCacheDuration added in v0.0.3

func SetCacheDuration(duration time.Duration)

SetCacheDuration 设置缓存的过期时间

func Split added in v0.0.6

func Split(str, delimiter string) []string

Split splits string `str` by a string `delimiter`, to an array.

func SplitAndTrim added in v0.0.6

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim splits string `str` by a string `delimiter` to an array, and calls Trim to every element of this array. It ignores the elements which are empty after Trim.

func SubString added in v0.0.3

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

SubString 截取字符串 参数:

  • str: 输入字符串
  • start: 起始位置
  • end: 结束位置(如果为-1,则截取到字符串末尾)

返回值:截取后的字符串

func Trim added in v0.0.7

func Trim(str string, characterMask ...string) string

Trim 从字符串的开头和结尾去除空白字符(或其他字符) 可选参数 characterMask 指定额外要去除的字符

func TrimAll added in v0.0.7

func TrimAll(str string, characterMask ...string) string

TrimAll 去除字符串中的所有指定字符

func TrimLeft added in v0.0.7

func TrimLeft(str string, characterMask ...string) string

TrimLeft 从字符串的开头去除空白字符(或其他字符)

func TrimLeftStr added in v0.0.7

func TrimLeftStr(str string, cut string, count ...int) string

TrimLeftStr 从字符串的开头去除所有给定的 cut 字符串 注意:它不会去除开头的空白字符

func TrimRight added in v0.0.7

func TrimRight(str string, characterMask ...string) string

TrimRight 从字符串的结尾去除空白字符(或其他字符)

func TrimRightStr added in v0.0.7

func TrimRightStr(str string, cut string, count ...int) string

TrimRightStr 从字符串的结尾去除所有给定的 cut 字符串 注意:它不会去除结尾的空白字符

func TrimStr added in v0.0.7

func TrimStr(str string, cut string, count ...int) string

TrimStr 从字符串的开头和结尾去除所有给定的 cut 字符串 注意:它不会去除开头或结尾的空白字符

func UnderLineName added in v0.0.3

func UnderLineName(name string) string

UnderLineName 将驼峰命名转换为下划线命名 参数:

  • name: 驼峰命名的字符串

返回值:下划线命名的字符串

Types

type WordRankResult added in v0.0.3

type WordRankResult struct {
	Text  string  `json:"text"`
	Count int     `json:"count"`
	Rank  float32 `json:"rank"`
}

WordRankResult 表示单词频率分析的结果

type WordRankResults added in v0.0.3

type WordRankResults []WordRankResult

WordRankResults 是 WordRankResult 的切片,实现了 sort.Interface

func WordRank added in v0.0.3

func WordRank(arrWords []string) WordRankResults

WordRank 对输入的单词切片进行词频分析 参数:

  • arrWords: 单词切片

返回值:按词频排序的 WordRankResults

func (WordRankResults) Len added in v0.0.3

func (s WordRankResults) Len() int

func (WordRankResults) Less added in v0.0.3

func (s WordRankResults) Less(i, j int) bool

func (WordRankResults) Swap added in v0.0.3

func (s WordRankResults) Swap(i, j int)

Jump to

Keyboard shortcuts

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