gstr

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 10 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 ClearWordRankCache added in v0.0.3

func ClearWordRankCache()

ClearWordRankCache 清除 WordRank 函数的缓存

func ExtractRegexMatch added in v0.0.3

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

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

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

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

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 HumpName added in v0.0.3

func HumpName(name string) string

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

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

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

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 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 SubString added in v0.0.3

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

SubString 截取字符串 参数:

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

返回值:截取后的字符串

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