Documentation
¶
Overview ¶
String utility pkg.
Index ¶
- func CamelCase(s string) string
- func ContainsAnyStr(s string, substrings ...string) bool
- func ContainsAnyStrIgnoreCase(s string, substrings ...string) bool
- func CutAfterLast(s string, sep string) string
- func CutPrefixIgnoreCase(s string, prefix string) (string, bool)
- func CutPrefixIgnoreCaseAny(s string, prefix ...string) (string, bool)
- func CutSuffixIgnoreCase(s string, suffix string) (string, bool)
- func CutSuffixIgnoreCaseAny(s string, suffix ...string) (string, bool)
- func EqualAnyFold(s string, canditates ...string) bool
- func EqualAnyStr(s string, canditates ...string) bool
- func EqualAnyStrSlice(s string, canditates []string) bool
- func FmtFloat(f float64, width int, precision int) string
- func HasAnyPrefix(s string, suf ...string) bool
- func HasAnySuffix(s string, suf ...string) bool
- func HasPrefixIgnoreCase(s string, prefix string) bool
- func HasSuffixIgnoreCase(s string, suffix string) bool
- func IsBlankStr(s string) bool
- func LastNStr(s string, n int) string
- func MatchPath(pattern, s string) bool
- func MatchPathAny(pattern []string, s string) bool
- func MatchPathAnyVal(pattern []string, s string) (string, bool)
- func MaxLenStr(s string, max int) string
- func NamedSprintf(pat string, p map[string]any) string
- func NamedSprintfkv[T constraint.BasicValue](pat string, kv ...T) string
- func NamedSprintfv(pat string, v any) string
- func NewReplacer(oldnew ...pair.StrPair) *strings.Replacer
- func PadNum(n int, digit int) string
- func PadSpace(n int, s string) string
- func PadToken(n int, s string, tok string) string
- func QuoteStr(s string) string
- func ReplaceAll(s string, oldnew ...pair.StrPair) string
- func RuneWidth(r rune) int
- func SAddLineIndent(s string, indentChar string) string
- func Spaces(count int) string
- func SplitKV(s string, token string) (string, string, bool)
- func SplitStr(s, sep string) []string
- func SplitStrAnyRune(s, runes string) []string
- func StrByteLen(s string) int
- func StrWidth(s string) int
- func Tabs(count int) string
- func ToStr(v any) string
- func TrimSpace(s string, extra ...rune) string
- func TrimSpaceAnd(s string, extraRunes string) stringdeprecated
- func TrimSpaceLeft(s string, extra ...rune) string
- func TrimSpaceRight(s string, extra ...rune) string
- func TrimStrSlice(s []string)
- func UnquoteStr(s string) string
- func UnsafeByt2Str(b []byte) string
- func UnsafeStr2Byt(s string) (b []byte)
- type Builder
- func (b *Builder) DecrIndent() *Builder
- func (b *Builder) IncrIndent() *Builder
- func (b *Builder) NewLine(st string) *Builder
- func (b *Builder) PPrintln(st string) *Builder
- func (b *Builder) PPrintlnf(st string, args ...any) *Builder
- func (b *Builder) Printf(st string, args ...any) *Builder
- func (b *Builder) Println(st string) *Builder
- func (b *Builder) Printlnf(st string, args ...any) *Builder
- func (b *Builder) StepIn(f func(b *Builder)) *Builder
- func (b *Builder) WithIndent(s string, c int) *Builder
- func (b *Builder) WithIndentCnt(ind int)
- func (b *Builder) WithIndentStr(ind string)
- func (b *Builder) WithLinePrefix(p string) *Builder
- func (b *Builder) WithLineSuffix(p string) *Builder
- type IndWritef
- type IndentWriter
- func (i *IndentWriter) DecrIndent()
- func (i *IndentWriter) IncrIndent()
- func (i *IndentWriter) NoIndWritef(pat string, args ...any) *IndentWriter
- func (i *IndentWriter) NoLbWritef(pat string, args ...any) *IndentWriter
- func (i *IndentWriter) NoLbWritefWhen(condition bool, pat string, args ...any) *IndentWriter
- func (i *IndentWriter) SetIndent(ind int)
- func (i *IndentWriter) StepIn(f func(iw *IndentWriter)) *IndentWriter
- func (i *IndentWriter) Writef(pat string, args ...any) *IndentWriter
- type SLPinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAnyStr ¶
func CutAfterLast ¶ added in v0.4.10
func CutPrefixIgnoreCase ¶
Cut prefix from s in a case-insensitive way.
func CutPrefixIgnoreCaseAny ¶
Cut any prefix from s in a case-insensitive way.
func CutSuffixIgnoreCase ¶
Cut suffix from s in a case-insensitive way.
func CutSuffixIgnoreCaseAny ¶
Cut any suffix from s in a case-insensitive way.
func EqualAnyFold ¶ added in v0.4.3
func EqualAnyStr ¶
func EqualAnyStrSlice ¶ added in v0.4.10
func HasAnyPrefix ¶
func HasAnySuffix ¶
func HasPrefixIgnoreCase ¶
Check if s has the prefix in a case-insensitive way.
func HasSuffixIgnoreCase ¶
Check if s has the suffix in a case-insensitive way.
func MatchPathAnyVal ¶ added in v0.3.4
Match any of the path pattern.
func NamedSprintf ¶
Format message using named args, e.g., '${startTime} ${message}'
func NamedSprintfkv ¶ added in v0.4.9
func NamedSprintfkv[T constraint.BasicValue](pat string, kv ...T) string
Format message using fields in struct, e.g., '${startTime} ${message}'
e.g.,
NamedSprintfkv("my name is ${name}", "name", "slim shady")
func NamedSprintfv ¶
Format message using fields in struct, e.g., '${startTime} ${message}'
Equivalent to following code:
NamedSprintf(pat, ReflectGenMap(myStruct))
func SAddLineIndent ¶
func SplitStrAnyRune ¶ added in v0.3.10
func TrimSpaceAnd
deprecated
added in
v0.4.3
func TrimSpaceLeft ¶ added in v0.3.4
func TrimSpaceRight ¶ added in v0.3.4
func TrimStrSlice ¶
func TrimStrSlice(s []string)
func UnquoteStr ¶
func UnsafeByt2Str ¶ added in v0.4.0
Convert []byte to string without alloc.
Both the []byte and the string share the same memory.
Any modification on the original []byte is reflected on the returned string.
byt = []byte("abc")
s = UnsafeByt2Str(byt) // "abc" using the same memory
byt[0] = 'd' // modified in place at 0, also reflected on s ("dbc")
Tricks from https://github.com/valyala/fasthttp and https://go101.org/article/unsafe.html
func UnsafeStr2Byt ¶ added in v0.4.0
Convert string to []byte without alloc.
Both the []byte and the string share the same memory.
The resulting []byte is not modifiable, program will panic if modified.
s := "abc" byt := UnsafeStr2Byt(s) // "abc" but in []byte byt[0] = 'd' // will panic
Tricks from https://github.com/valyala/fasthttp and https://go101.org/article/unsafe.html
Types ¶
type Builder ¶ added in v0.4.12
Enhanced strings.Builder.
Use NewBuilder instantiate.
func NewBuilder ¶ added in v0.4.11
func NewBuilder() *Builder
func (*Builder) DecrIndent ¶ added in v0.4.12
func (*Builder) IncrIndent ¶ added in v0.4.12
func (*Builder) PPrintln ¶ added in v0.4.13
Add new content.
Only add line break at the start if the builder is not empty.
func (*Builder) PPrintlnf ¶ added in v0.4.13
Add new formatted content
Only add line break at the start if the builder is not empty.
func (*Builder) Println ¶ added in v0.4.12
Add new content.
Always add line break at the end of the line.
func (*Builder) Printlnf ¶ added in v0.4.12
Add new formatted content.
Always add line break at the end of the line.
func (*Builder) WithIndent ¶ added in v0.4.12
func (*Builder) WithIndentCnt ¶ added in v0.4.12
func (*Builder) WithIndentStr ¶ added in v0.4.12
func (*Builder) WithLinePrefix ¶ added in v0.4.12
func (*Builder) WithLineSuffix ¶ added in v0.4.12
type IndentWriter ¶
func NewIndentWriter ¶
func NewIndentWriter(indentStr string) IndentWriter
func (*IndentWriter) DecrIndent ¶
func (i *IndentWriter) DecrIndent()
func (*IndentWriter) IncrIndent ¶
func (i *IndentWriter) IncrIndent()
func (*IndentWriter) NoIndWritef ¶
func (i *IndentWriter) NoIndWritef(pat string, args ...any) *IndentWriter
Writef without indentation and with line break.
func (*IndentWriter) NoLbWritef ¶
func (i *IndentWriter) NoLbWritef(pat string, args ...any) *IndentWriter
Writef with indentation and without line break.
func (*IndentWriter) NoLbWritefWhen ¶
func (i *IndentWriter) NoLbWritefWhen(condition bool, pat string, args ...any) *IndentWriter
NoLbWritef(..) when condition is true else Writef(..).
func (*IndentWriter) SetIndent ¶
func (i *IndentWriter) SetIndent(ind int)
func (*IndentWriter) StepIn ¶
func (i *IndentWriter) StepIn(f func(iw *IndentWriter)) *IndentWriter
func (*IndentWriter) Writef ¶
func (i *IndentWriter) Writef(pat string, args ...any) *IndentWriter