stringx

package
v0.0.0-...-8cfda75 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MIT Imports: 6 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsciiEqualFold

func AsciiEqualFold(s, t []byte) bool

AsciiEqualFold is a specialization of bytes.EqualFold for use when s is all ASCII (but may contain non-letters) and contains no special-folding letters. See comments on FoldFunc.

func EqualFoldRight

func EqualFoldRight(s, t []byte) bool

EqualFoldRight is a specialization of bytes.EqualFold when s is known to be all ASCII (including punctuation), but contains an 's', 'S', 'k', or 'K', requiring a Unicode fold on the bytes in t. See comments on FoldFunc.

func FoldFunc

func FoldFunc(s []byte) func(s, t []byte) bool

FoldFunc returns one of four different case folding equivalence functions, from most general (and slow) to fastest:

1) bytes.EqualFold, if the key s contains any non-ASCII UTF-8 2) EqualFoldRight, if s contains special folding ASCII ('k', 'K', 's', 'S') 3) AsciiEqualFold, no special, but includes non-letters (including _) 4) SimpleLetterEqualFold, no specials, no non-letters.

The letters S and K are special because they map to 3 runes, not just 2:

  • S maps to s and to U+017F 'ſ' Latin small letter long s
  • k maps to K and to U+212A 'K' Kelvin sign

See https://play.golang.org/p/tTxjOc0OGo

The returned function is specialized for matching against s and should only be given s. It's not curried for performance reasons.

func Indices

func Indices(str, substr string) []int

func IsAllBlank

func IsAllBlank[S ~string](ss ...S) bool

IsAllBlank Checks if all of the CharSequences are empty ("") or whitespace only.

func IsAllEmpty

func IsAllEmpty[S ~string](ss ...S) bool

IsAllEmpty Checks if all of the strings are empty ("")

func IsAnyBlank

func IsAnyBlank[S ~string](ss ...S) bool

IsAnyBlank Checks if any of the string are empty ("") or whitespace only.

func IsAnyEmpty

func IsAnyEmpty[S ~string](ss ...S) bool

IsAnyEmpty Checks if any of the strings are empty ("")

func IsBlank

func IsBlank[S ~string](s S) bool

IsBlank Checks if a string is empty ("") or whitespace only.

func IsEmpty

func IsEmpty[S ~string](s S) bool

IsEmpty checks if a string is empty ("")

func IsNotBlank

func IsNotBlank[S ~string](s S) bool

IsNotBlank Checks if a string is not empty ("") and not whitespace only.

func IsNotEmpty

func IsNotEmpty[S ~string](s S) bool

IsNotEmpty Checks if a string is not empty ("")

func IsValidNumber

func IsValidNumber(s string) bool

IsValidNumber reports whether s is a valid number.

func Match

func Match(str string, pattern string) []string

func Remove

func Remove(s string, chars string) string

Remove takes a string candidate and a string of chars to remove from the candidate.

func ReplaceFunc

func ReplaceFunc(str string, f func(rune) string) string

func SimpleLetterEqualFold

func SimpleLetterEqualFold(s, t []byte) bool

SimpleLetterEqualFold is a specialization of bytes.EqualFold for use when s is all ASCII letters (no underscores, etc) and also doesn't contain 'k', 'K', 's', or 'S'. See comments on FoldFunc.

func SnackCase

func SnackCase(s string) string

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func NewBuilderBuilder

func NewBuilderBuilder(b *strings.Builder) *Builder

func (*Builder) Cap

func (b *Builder) Cap() int

Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.

func (*Builder) Grow

func (b *Builder) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*Builder) Len

func (b *Builder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*Builder) Reset

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) String

func (b *Builder) String() string

String returns the accumulated string.

func (*Builder) Write

func (b *Builder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*Builder) WriteBool

func (b *Builder) WriteBool(bl bool) error

WriteBool appends "true" or "false".

func (*Builder) WriteByte

func (b *Builder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*Builder) WriteFloat

func (b *Builder) WriteFloat(f float64, fmt byte, prec, bitSize int) error

WriteFloat appends the string form of the floating-point number f.

func (*Builder) WriteInt

func (b *Builder) WriteInt(i int64, base int) error

WriteInt appends the string form of the integer i.

func (*Builder) WriteQuote

func (b *Builder) WriteQuote(s string) error

WriteQuote appends a double-quoted Go string literal representing s.

func (*Builder) WriteQuoteRune

func (b *Builder) WriteQuoteRune(r rune) error

WriteQuoteRune appends a single-quoted Go character literal representing the rune.

func (*Builder) WriteQuoteRuneToASCII

func (b *Builder) WriteQuoteRuneToASCII(r rune) error

WriteQuoteRuneToASCII appends a single-quoted Go character literal representing the rune.

func (*Builder) WriteQuoteRuneToGraphic

func (b *Builder) WriteQuoteRuneToGraphic(r rune) error

WriteQuoteRuneToGraphic appends a single-quoted Go character literal representing the rune.

func (*Builder) WriteQuoteToASCII

func (b *Builder) WriteQuoteToASCII(s string) error

WriteQuoteToASCII appends a double-quoted Go string literal representing s.

func (*Builder) WriteQuoteToGraphic

func (b *Builder) WriteQuoteToGraphic(s string) error

WriteQuoteToGraphic appends a double-quoted Go string literal representing s.

func (*Builder) WriteRune

func (b *Builder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*Builder) WriteString

func (b *Builder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

func (*Builder) WriteUint

func (b *Builder) WriteUint(i uint64, base int) error

WriteUint appends the string form of the unsigned integer i.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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