strings

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 16 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool added in v1.11.0

func Bool(value string) (bool, error)

Bool performs the operation.

func BoolP added in v1.11.0

func BoolP(value string) (*bool, error)

BoolP performs the operation.

func BoolSlice added in v1.11.0

func BoolSlice(val, sep string) ([]bool, error)

BoolSlice converts 'val' where individual booleans are separated by 'sep' into a bool slice.

func BracketsIntervals

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

BracketsIntervals performs the operation.

func Bytes added in v1.11.0

func Bytes(val string) ([]byte, error)

Bytes converts the given string representation of a byte sequence into a slice of bytes A bytes sequence is encoded in URL-safe base64 without padding

func BytesSlice added in v1.11.0

func BytesSlice(val, sep string) ([][]byte, error)
BytesSlice converts 'val' where individual bytes sequences, encoded in URL-safe

base64 without padding, are separated by 'sep' into a slice of bytes slices slice.

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

CamelCaseSlice returns the result.

func CamelToSnake

func CamelToSnake(name string) string

CamelToSnake returns the result.

func CommonRuneHandler

func CommonRuneHandler(s string, rm func(r rune) bool) string

CommonRuneHandler returns the result.

func CommonRuneReplace

func CommonRuneReplace(s string, f func(r rune) rune) string

CommonRuneReplace returns the result.

func Cut

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

Cut performs the operation.

func CutPart

func CutPart(s, sep string) string

CutPart returns the result.

func CutPartContain

func CutPartContain(s, sep string) string

CutPartContain returns the result.

func DJB33

func DJB33(seed uint32, k string) uint32

DJB33 returns the result.

func Float added in v1.11.0

func Float[T constraints.Float](value string) (T, error)

Float performs the operation.

func Float32 added in v1.11.0

func Float32(val string) (float32, error)

Float32 converts the given string representation of a floating point number into float32.

func Float32P added in v1.11.0

func Float32P(val string) (*float32, error)

Float32P performs the operation.

func Float32Slice added in v1.11.0

func Float32Slice(val, sep string) ([]float32, error)

Float32Slice converts 'val' where individual floating point numbers are separated by 'sep' into a float32 slice.

func Float64 added in v1.11.0

func Float64(val string) (float64, error)

Float64 converts the given string representation into representation of a floating point number into float64.

func Float64P added in v1.11.0

func Float64P(val string) (*float64, error)

Float64P performs the operation.

func Float64Slice added in v1.11.0

func Float64Slice(val, sep string) ([]float64, error)

Float64Slice converts 'val' where individual floating point numbers are separated by 'sep' into a float64 slice.

func FloatP added in v1.11.0

func FloatP[T constraints.Float](value string) (*T, error)

FloatP performs the operation.

func FloatSlice added in v1.11.0

func FloatSlice[T constraints.Float](val, sep string) ([]T, error)

FloatSlice converts 'val' where individual floating point numbers are separated by 'sep' into a float slice.

func Format added in v1.11.0

func Format(t any) string

Format formats or converts the value.

func FormatInteger added in v1.11.0

func FormatInteger(value any) string

FormatInteger formats or converts the value.

func FormatLen

func FormatLen(s string, length int) string

FormatLen formats or converts the value.

func FormatReflectValue added in v1.11.0

func FormatReflectValue(value reflect.Value) string

FormatReflectValue formats or converts the value.

func FormatSigned added in v1.11.0

func FormatSigned[T constraints.Signed](v T) string

FormatSigned formats or converts the value.

func FormatUnsigned added in v1.11.0

func FormatUnsigned[T constraints.Unsigned](v T) string

FormatUnsigned formats or converts the value.

func FromBytes

func FromBytes(b []byte) string

func HasPrefixes

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

HasPrefixes reports whether the condition holds.

func Int added in v1.11.0

func Int(val string) (int, error)

Int performs the operation.

func Int8 added in v1.11.0

func Int8(val string) (int8, error)

Int8 performs the operation.

func Int8P added in v1.11.0

func Int8P(val string) (*int8, error)

Int8P performs the operation.

func Int8Slice added in v1.11.0

func Int8Slice(val, sep string) ([]int8, error)

Int8Slice converts 'val' where individual integers are separated by 'sep' into a int8 slice.

func Int16 added in v1.11.0

func Int16(val string) (int16, error)

Int16 performs the operation.

func Int16P added in v1.11.0

func Int16P(val string) (*int16, error)

Int16P performs the operation.

func Int16Slice added in v1.11.0

func Int16Slice(val, sep string) ([]int16, error)

Int16Slice converts 'val' where individual integers are separated by 'sep' into a int slice.

func Int32 added in v1.11.0

func Int32(val string) (int32, error)

Int32 converts the given string representation of an integer into int32.

func Int32P added in v1.11.0

func Int32P(val string) (*int32, error)

Int32P performs the operation.

func Int32Slice added in v1.11.0

func Int32Slice(val, sep string) ([]int32, error)

Int32Slice converts 'val' where individual integers are separated by 'sep' into a int32 slice.

func Int64 added in v1.11.0

func Int64(val string) (int64, error)

Int64 converts the given string representation of an integer into int64.

func Int64P added in v1.11.0

func Int64P(val string) (*int64, error)

Int64P performs the operation.

func Int64Slice added in v1.11.0

func Int64Slice(val, sep string) ([]int64, error)

Int64Slice converts 'val' where individual integers are separated by 'sep' into a int64 slice.

func IntP added in v1.11.0

func IntP(val string) (*int, error)

IntP performs the operation.

func IntSlice added in v1.11.0

func IntSlice(val, sep string) ([]int, error)

IntSlice converts 'val' where individual integers are separated by 'sep' into a int slice.

func IsEmpty

func IsEmpty(str string) bool

IsEmpty reports whether the condition holds.

func IsNumber

func IsNumber(str string) bool

IsNumber reports whether the condition holds.

func IsQuoted

func IsQuoted[T ~string | ~[]byte](s T) bool

IsQuoted reports whether the condition holds.

func Join

func Join[S ~[]T, T fmt.Stringer](s S, sep string) string

Join returns the result.

func JoinFunc added in v1.7.0

func JoinFunc[S ~[]T, T any](s S, toString func(idx int, v T) string, sep string) string

JoinFunc returns the result.

func JoinIndexFunc added in v1.7.0

func JoinIndexFunc[S ~[]T, T any](s S, toString func(i int) string, sep string) string

JoinIndexFunc returns the result.

func JoinValueFunc added in v1.7.0

func JoinValueFunc[S ~[]T, T any](s S, toString func(v T) string, sep string) string

JoinValueFunc returns the result.

func LowerCase

func LowerCase(c byte) byte

LowerCase returns the result.

func LowerCaseFirst

func LowerCaseFirst(t string) string

LowerCaseFirst returns the result.

func ParseFor added in v1.11.0

func ParseFor[T any](str string) (T, error)

ParseFor parses the input.

func ParsePtrFor added in v1.11.0

func ParsePtrFor[T any](str string) (*T, error)

ParsePtrFor parses the input.

func Rand

func Rand(length int) string

Rand returns the result.

func RemoveEmoji

func RemoveEmoji(s string) string

RemoveEmoji removes or resets state.

func RemoveRunes

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

RemoveRunes removes or resets state.

func RemoveSymbol

func RemoveSymbol(s string) string

RemoveSymbol removes or resets state.

func ReplaceBytes

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

ReplaceBytes returns the result.

func ReplaceBytesEmpty

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

ReplaceBytesEmpty returns the result.

func ReplaceRunes

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

TODO

func RetainHanAndASCII

func RetainHanAndASCII(s string) string

RetainHanAndASCII returns the result.

func RetainHanAndASCIIGt32

func RetainHanAndASCIIGt32(s string) string

RetainHanAndASCIIGt32 returns the result.

func ReverseCut

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

ReverseCut performs the operation.

func ReverseCutPart

func ReverseCutPart(s, key string) string

ReverseCutPart returns the result.

func Signed added in v1.11.0

func Signed[T constraints.Signed](value string) (T, error)

Signed performs the operation.

func SignedP added in v1.11.0

func SignedP[T constraints.Signed](value string) (*T, error)

SignedP performs the operation.

func SignedSlice added in v1.11.0

func SignedSlice[T constraints.Signed](val, sep string) ([]T, error)

SignedSlice converts 'val' where individual integers are separated by 'sep' into a Signed slice.

func SnakeToCamel

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

SnakeToCamel returns the result.

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", "Chinese"]
"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 String added in v1.11.0

func String(val string) (string, error)

String returns the string representation.

func StringSlice added in v1.11.0

func StringSlice(val, sep string) ([]string, error)

StringSlice converts 'val' where individual strings are separated by 'sep' into a string slice.

func ToBytes

func ToBytes(s string) []byte

func Uint added in v1.11.0

func Uint(val string) (uint, error)

Uint performs the operation.

func Uint8 added in v1.11.0

func Uint8(val string) (uint8, error)

Uint8 performs the operation.

func Uint8P added in v1.11.0

func Uint8P(val string) (*uint8, error)

Uint8P performs the operation.

func Uint8Slice added in v1.11.0

func Uint8Slice(val, sep string) ([]uint8, error)

Uint8Slice converts 'val' where individual integers are separated by 'sep' into a uint8 slice.

func Uint16 added in v1.11.0

func Uint16(val string) (uint16, error)

Uint16 performs the operation.

func Uint16P added in v1.11.0

func Uint16P(val string) (*uint16, error)

Uint16P performs the operation.

func Uint16Slice added in v1.11.0

func Uint16Slice(val, sep string) ([]uint16, error)

Uint16Slice converts 'val' where individual integers are separated by 'sep' into a uint slice.

func Uint32 added in v1.11.0

func Uint32(val string) (uint32, error)

Uint32 converts the given string representation of an integer into uint32.

func Uint32P added in v1.11.0

func Uint32P(val string) (*uint32, error)

Uint32P performs the operation.

func Uint32Slice added in v1.11.0

func Uint32Slice(val, sep string) ([]uint32, error)

Uint32Slice converts 'val' where individual integers are separated by 'sep' into a uint32 slice.

func Uint64 added in v1.11.0

func Uint64(val string) (uint64, error)

Uint64 converts the given string representation of an integer into uint64.

func Uint64P added in v1.11.0

func Uint64P(val string) (*uint64, error)

Uint64P performs the operation.

func Uint64Slice added in v1.11.0

func Uint64Slice(val, sep string) ([]uint64, error)

Uint64Slice converts 'val' where individual integers are separated by 'sep' into a uint64 slice.

func UintP added in v1.11.0

func UintP(val string) (*uint, error)

UintP performs the operation.

func UintSlice added in v1.11.0

func UintSlice(val, sep string) ([]uint, error)

UintSlice converts 'val' where individual integers are separated by 'sep' into a uint slice.

func UnSigned added in v1.11.0

func UnSigned[T constraints.Unsigned](value string) (T, error)

UnSigned performs the operation.

func UnSignedP added in v1.11.0

func UnSignedP[T constraints.Unsigned](value string) (*T, error)

UnSignedP performs the operation.

func UnsignedSlice added in v1.11.0

func UnsignedSlice[T constraints.Unsigned](val, sep string) ([]T, error)

UnsignedSlice converts 'val' where individual integers are separated by 'sep' into a Unsigned slice.

func UpperCase

func UpperCase(c byte) byte

UpperCase returns the result.

func UpperCaseFirst

func UpperCaseFirst(t string) string

UpperCaseFirst returns the result.

Types

type NumLetterSlice

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

func (*NumLetterSlice[T]) Set

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

Set updates or inserts a value.

Jump to

Keyboard shortcuts

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