strs

package
v0.0.0-...-c6a0258 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Windows = runtime.GOOS == "windows"

Functions

func AnySet

func AnySet(dst any, val string, valueAppend bool)

func Bool

func Bool[T ~bool](s string, def ...T) (r T)

func Bytes

func Bytes(s string) []byte

Bytes 使用 unsafe 将 string 转换为 []byte

func Compaare

func Compaare(a, b string) int

Compare returns an integer comparing two strings lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.

Use Compare when you need to perform a three-way comparison (with slices.SortFunc, for example). It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

func Cut

func Cut(s, sep string) (prefix, suffix string, ok bool)

Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.

func Duration

func Duration(t time.Duration) string

func Equal

func Equal(a, b string) bool

Equal returns true if a and b are equal, case-insensitive on Windows.

func Fields

func Fields(s string) []string

Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space.

func FieldsFunc

func FieldsFunc(s string, f func(rune) bool) []string

FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned.

FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.

func Float

func Float[T ~float32 | ~float64](s string, def ...T) (r T)

func FromBytes

func FromBytes(b []byte) string

func FromInt

func FromInt[T Ints](i T, base int) string

func FromUint

func FromUint[T Uints](i T, base int) string

func HasPrefix

func HasPrefix(s string, prefix string) bool

HasPrefix reports whether the string s begins with prefix. case-insensitive on Windows.

func HasSuffix

func HasSuffix(s string, suffix string) bool

HasSuffix reports whether the string s ends with suffix. case-insensitive on Windows.

func Index

func Index(s string, substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

func IndexFunc

func IndexFunc(s string, f func(rune) bool) int

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

func Int

func Int[T Ints](s string, def ...T) (r T)

func Join

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

Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.

func Lower

func Lower(s string) string

Lower returns s with all Unicode letters mapped to their lower case.

func ParseDuration

func ParseDuration(s string) (t time.Duration, err error)

func ParseIP

func ParseIP(val string) (net.IP, error)

func Percent

func Percent(cur, total int64) string

func Prefix

func Prefix(s string, sep string) string

Prefix returns the left part of the string before the first occurrence of the separator.

func Prefix2

func Prefix2(s1, s2 string, sep string) (string, string)

Prefix2 returns the left part of the string before the first occurrence of the separator.

func PrefixMatch

func PrefixMatch(prefix ...string) func(string) bool

PrefixMatch returns a function that returns true if the given string starts with any of the given prefixes.

func Replace

func Replace(s, old, new string, n ...int) string

Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, or len(n) == 0 there is no limit on the number of replacements.

func Size

func Size(bytes int64) string

Size 将文件大小转换为人类可读的格式

func Split

func Split(s, sep string) []string

Split splits a string into a slice of strings. return nil if the string is empty.

func Suffix

func Suffix(s string, sep string) string

Suffix returns the right part of the string after the first occurrence of the separator.

func Suffix2

func Suffix2(s1, s2 string, sep string) (string, string)

Suffix2 returns the right part of the string after the first occurrence of the separator.

func SuffixMatch

func SuffixMatch(suffix string) func(string) bool

SuffixMatch returns a function that returns true if the given string ends with the given suffix.

func TrimExe

func TrimExe(s string) string

func TrimFunc

func TrimFunc(s string, f func(rune) bool) string

TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.

func TrimPrefix

func TrimPrefix(s, prefix string) string

TrimPrefix returns s without the provided leading prefix string. case-insensitive on Windows.

func TrimSpace

func TrimSpace(s string) string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func TrimSuffix

func TrimSuffix(s, suffix string) string

TrimSuffix returns s without the provided trailing suffix string. case-insensitive on Windows.

func Uint

func Uint[T Uints](s string, def ...T) (r T)

func Upper

func Upper(s string) string

Upper returns s with all Unicode letters mapped to their upper case.

Types

type Floats

type Floats interface{ ~float32 | ~float64 }

type Ints

type Ints interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Setter

type Setter[T any] struct{ Set func(T, error) }

func NumSet

func NumSet[T, R Ints | Uints | Floats](dst *R) (setter Setter[T])

func SameSet

func SameSet[T any](dst *T) (setter Setter[T])

func SameSets

func SameSets[T any](dst *[]T, valueAppend bool) (setter Setter[T])

func Sets

func Sets[T, R Ints | Uints | Floats](dst *[]R, valueAppend bool) (setter Setter[T])

type Strs

type Strs interface{ ~string | ~[]byte }

type Uints

type Uints interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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