strutil

package
v0.3.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

func ContainsAnyStr

func ContainsAnyStr(s string, substrings ...string) bool

func ContainsAnyStrIgnoreCase

func ContainsAnyStrIgnoreCase(s string, substrings ...string) bool

func CutPrefixIgnoreCase

func CutPrefixIgnoreCase(s string, prefix string) (string, bool)

Cut prefix from s in a case-insensitive way.

func CutPrefixIgnoreCaseAny

func CutPrefixIgnoreCaseAny(s string, prefix ...string) (string, bool)

Cut any prefix from s in a case-insensitive way.

func CutSuffixIgnoreCase

func CutSuffixIgnoreCase(s string, suffix string) (string, bool)

Cut suffix from s in a case-insensitive way.

func CutSuffixIgnoreCaseAny

func CutSuffixIgnoreCaseAny(s string, suffix ...string) (string, bool)

Cut any suffix from s in a case-insensitive way.

func EqualAnyStr

func EqualAnyStr(s string, canditates ...string) bool

func FmtFloat

func FmtFloat(f float64, width int, precision int) string

func HasAnyPrefix

func HasAnyPrefix(s string, suf ...string) bool

func HasAnySuffix

func HasAnySuffix(s string, suf ...string) bool

func HasPrefixIgnoreCase

func HasPrefixIgnoreCase(s string, prefix string) bool

Check if s has the prefix in a case-insensitive way.

func HasSuffixIgnoreCase

func HasSuffixIgnoreCase(s string, suffix string) bool

Check if s has the suffix in a case-insensitive way.

func IsBlankStr

func IsBlankStr(s string) bool

Check if the string is blank

func LastNStr

func LastNStr(s string, n int) string

func MatchPath

func MatchPath(pattern, s string) bool

func MatchPathAny

func MatchPathAny(pattern []string, s string) bool

func MaxLenStr

func MaxLenStr(s string, max int) string

Substring such that len(s) <= max

func NamedSprintf

func NamedSprintf(pat string, p map[string]any) string

Format message using named args, e.g., '${startTime} ${message}'

func NamedSprintfv

func NamedSprintfv(pat string, v any) string

Format message using fields in struct, e.g., '${startTime} ${message}'

Equivalent to following code:

NamedSprintf(pat, ReflectGenMap(myStruct))

func PadNum

func PadNum(n int, digit int) string

func PadSpace

func PadSpace(n int, s string) string

func PadToken

func PadToken(n int, s string, tok string) string

func QuoteStr

func QuoteStr(s string) string

func RuneWidth

func RuneWidth(r rune) int

func SAddLineIndent

func SAddLineIndent(s string, indentChar string) string

func Spaces

func Spaces(count int) string

func SplitKV

func SplitKV(s string, token string) (string, string, bool)

Splist kv pair. Returns false if token is not found or key is absent.

func SplitStr

func SplitStr(s, sep string) []string

func StrWidth

func StrWidth(s string) int

func Tabs

func Tabs(count int) string

func ToStr

func ToStr(v any) string

func TrimStrSlice

func TrimStrSlice(s []string)

func UnquoteStr

func UnquoteStr(s string) string

Types

type IndWritef

type IndWritef = func(indentCnt int, pat string, args ...any)

func NewIndWritef

func NewIndWritef(indentStr string) (*strings.Builder, IndWritef)

Wrap strings.Builder, and returns a Writef func that automatically adds indentation.

type IndentWriter

type IndentWriter struct {
	*strings.Builder
	// contains filtered or unexported fields
}

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

type SLPinter

type SLPinter struct {
	*strings.Builder
	LineSuffix string
	LinePrefix string
}

func (*SLPinter) Printf

func (s *SLPinter) Printf(st string, args ...any)

func (*SLPinter) Println

func (s *SLPinter) Println(st string)

func (*SLPinter) Printlnf

func (s *SLPinter) Printlnf(st string, args ...any)

Jump to

Keyboard shortcuts

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