strings

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT, Apache-2.0 Imports: 9 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HanPunctuation = []rune{
	'\u3002', '\uff1b', '\uff0c', '\uff1a', '\u201c', '\u201d', '\uff08', '\uff09', '\u3001', '\uff1f', '\u300a', '\u300b',
}

[。;,:“”()、?《》]

Functions

func AnchorName

func AnchorName(text string) string

Create returns a sanitized anchor name for the given text.

func BracketsIntervals

func BracketsIntervals(s string, tokenBegin, tokenEnd rune) (string, bool)

寻找括号区间 BracketsIntervals 在给定字符串中寻找由特定开始和结束符号包围的区间。 它会返回第一个找到的由tokenBegin和tokenEnd界定的字符串区间, 如果找到了则返回该区间和true,否则返回空字符串和false。

参数: s - 待搜索的字符串。 tokenBegin - 搜索的开始符号。 tokenEnd - 搜索的结束符号。

返回值: 第一个找到的由tokenBegin和tokenEnd界定的字符串区间, 如果找到了则返回该区间和true,否则返回空字符串和false。

func BytesFrom

func BytesFrom(p unsafe.Pointer, n int, c int) (r []byte)

func BytesToString

func BytesToString(b []byte) string

func CamelCase

func CamelCase(s string) string

CamelCase camel-cases a protobuf name for use as a Go identifier.

If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.

func CamelCaseSlice

func CamelCaseSlice(elem []string) string

func CamelToSnake

func CamelToSnake(name string) string

func Cut

func Cut(s, sep string) (string, string, bool)

func CutPart

func CutPart(s, sep string) string

指定字符截断,返回阶段前的字符串 CutPart("https://wx1.sinaimg.cn/orj360/6ebedee6ly1h566bbzyc6j20n00cuabd.jpg", "wx1") https://

func FormatLen

func FormatLen(s string, length int) string

func HasHan

func HasHan(s string) bool

func HasPrefixes

func HasPrefixes(s string, prefixes []string) bool

有一个匹配成功就返回true

func IndexByte

func IndexByte(ptr []byte, index int) unsafe.Pointer

func IndexChar

func IndexChar(src string, index int) unsafe.Pointer

func IsASCIIDigit

func IsASCIIDigit(c byte) bool

Is c an ASCII digit?

func IsASCIILetter

func IsASCIILetter(c byte) bool

func IsASCIILetters

func IsASCIILetters(s string) bool

func IsASCIILower

func IsASCIILower(c byte) bool

Is c an ASCII lower-case letter?

func IsASCIILowers

func IsASCIILowers(s string) bool

func IsASCIIUpper

func IsASCIIUpper(c byte) bool

func IsASCIIUppers

func IsASCIIUppers(s string) bool

func LowerCase

func LowerCase(c byte) byte

func LowerCaseFirst

func LowerCaseFirst(t string) string

仅首位小写(更符合接口的规范)

func Mem2Str

func Mem2Str(v []byte) (s string)

func QuoteToBytes

func QuoteToBytes(s string) []byte

func Rand

func Rand(length int) string

func ReplaceBytes

func ReplaceBytes(s string, olds []byte, new byte) string

func ReplaceBytesEmpty

func ReplaceBytesEmpty(s string, old ...byte) string

将字符串中指定的ascii字符替换为空

func ReplaceRunes

func ReplaceRunes(s string, olds []rune, new rune) string

TODO

func ReplaceRunesEmpty

func ReplaceRunesEmpty(s string, old ...rune) string

func ReverseCut

func ReverseCut(s, sep string) (string, string, bool)

func ReverseCutPart

func ReverseCutPart(s, key string) string

从字符串尾开始,返回指定字符截断后的字符串 ReverseCutPart("https://video.weibo.com/media/play?livephoto=https%3A%2F%2Flivephoto.us.sinaimg.cn%2F002OnXdGgx07YpcajtkH0f0f0100gv8Q0k01.mov", "%2F") 002OnXdGgx07YpcajtkH0f0f0100gv8Q0k01.mov

func SnakeToCamel

func SnakeToCamel[T ~string](s T) string

func SplitCamelCase

func SplitCamelCase(src string) (entries []string)

Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase

Examples

"" =>                     [""]
"lowercase" =>            ["lowercase"]
"Class" =>                ["Class"]
"MyClass" =>              ["My", "Class"]
"MyC" =>                  ["My", "C"]
"HTML" =>                 ["HTML"]
"PDFLoader" =>            ["PDF", "Loader"]
"AString" =>              ["A", "String"]
"SimpleXMLParser" =>      ["Simple", "XML", "Parser"]
"vimRPCPlugin" =>         ["vim", "RPC", "Plugin"]
"GL11Version" =>          ["GL", "11", "Version"]
"99Bottles" =>            ["99", "Bottles"]
"May5" =>                 ["May", "5"]
"BFG9000" =>              ["BFG", "9000"]
"BöseÜberraschung" =>     ["Böse", "Überraschung"]
"Two  spaces" =>          ["Two", "  ", "spaces"]
"BadUTF8\xe2\xe2\xa1" =>  ["BadUTF8\xe2\xe2\xa1"]

Splitting rules

  1. If string is not valid UTF-8, return it without splitting as single item array.
  2. Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
  3. Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
  4. Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string

func Str2Mem

func Str2Mem(s string) (v []byte)

func StrFrom

func StrFrom(p unsafe.Pointer, n int64) (s string)

func StrPtr

func StrPtr(s string) unsafe.Pointer

func StringToBytes

func StringToBytes(s string) []byte

func ToBytes

func ToBytes(s string) []byte

func ToLowerFirst

func ToLowerFirst(s string) string

func ToString

func ToString(b []byte) string

func ToUnicode

func ToUnicode(s []byte) string

func Unquote

func Unquote(s []byte) (t string, ok bool)

unquote converts a quoted JSON string literal s into an actual string t. The rules are different than for Go, so cannot use strconv.Unquote.

func UpperCase

func UpperCase(c byte) byte

func UpperCaseFirst

func UpperCaseFirst(t string) string

Types

type NumLetterSlice

type NumLetterSlice[T any] ['z' - '0' + 1]T

func (*NumLetterSlice[T]) Set

func (n *NumLetterSlice[T]) Set(b byte, v T)

原来数组支持这样用

Directories

Path Synopsis
encoding
gbk
Match provides a simple pattern matcher with unicode support.
Match provides a simple pattern matcher with unicode support.

Jump to

Keyboard shortcuts

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