Documentation ¶
Index ¶
- func AppendIfMissing(str string, suffix string) string
- func AppendIfNotEmpty(str string, suffix string) string
- func CamelToSnake(s string) string
- func Capitalize(str string) string
- func Contains(str string, sub string) bool
- func ContainsAny(str string, subStrings []string) bool
- func Copy(s string) string
- func DeCapitalize(str string) string
- func Decode(data []byte, enc encoding.Encoding) (string, error)
- func Encode(str string, enc encoding.Encoding) ([]byte, error)
- func FirstNonEmpty(s1, s2 string) string
- func FromBytes(bytes []byte) string
- func PadLeft(str string, width int, r rune) string
- func PadRight(str string, width int, r rune) string
- func PadToCenter(str string, width int, r rune) string
- func PrependIfMissing(str string, prefix string) string
- func PrependIfNotEmpty(str string, prefix string) string
- func Slice(str string, begin, end int) string
- func SliceToEnd(str string, begin int) string
- func SnakeToCamel(s string, capitalized bool) string
- func SubstringAfter(str string, sep string) string
- func SubstringAfterLast(str string, sep string) string
- func SubstringBefore(str string, sep string) string
- func SubstringBeforeLast(str string, sep string) string
- func ToBytes(str string) []byte
- func ValueOf(v interface{}) string
- type JoinBuffer
- func (j *JoinBuffer) Add(str string) *JoinBuffer
- func (j *JoinBuffer) AddAll(ss ...string) *JoinBuffer
- func (j *JoinBuffer) AddAllAny(ss ...interface{}) *JoinBuffer
- func (j *JoinBuffer) AddAllStringer(ss ...fmt.Stringer) *JoinBuffer
- func (j *JoinBuffer) AddAny(value interface{}) *JoinBuffer
- func (j *JoinBuffer) AddBytes(data []byte) *JoinBuffer
- func (j *JoinBuffer) AddInt(value int) *JoinBuffer
- func (j *JoinBuffer) AddInt64(value int64) *JoinBuffer
- func (j *JoinBuffer) AddStringer(value fmt.Stringer) *JoinBuffer
- func (j *JoinBuffer) AddUint(value uint) *JoinBuffer
- func (j *JoinBuffer) AddUint64(value uint64) *JoinBuffer
- func (j *JoinBuffer) Reset() *JoinBuffer
- func (j *JoinBuffer) String() string
- type Joiner
- type Splitter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIfMissing ¶
AppendIfMissing return a str end with suffix appended if not has the suffix; otherwise return str it's self
func AppendIfNotEmpty ¶ added in v1.3.0
AppendIfNotEmpty return str with suffix if str is not empty; return the origin str otherwise.
func CamelToSnake ¶ added in v1.4.0
CamelToSnake convert camel style ascii str to underscore snake style.
func Capitalize ¶ added in v1.3.0
Capitalize return str with first char of ascii str upper case.
func ContainsAny ¶ added in v1.8.2
ContainsAny return whether str contains any one of subStrings.
func Copy ¶ added in v1.4.0
Copy deep copy a string, for reducing large string content memory usage when do substring. This method allocate a new string content byte array, thereby allow the larger string to be released by the garbage collector once it is no longer referenced
func DeCapitalize ¶ added in v1.3.0
DeCapitalize return str with first char of ascii str lower case.
func FirstNonEmpty ¶ added in v1.7.0
FirstNonEmpty return first non-empty string; If all string is empty, return empty string.
func FromBytes ¶ added in v1.8.2
FromBytes unsafe convert byte array content to string This function do not allocate new buffer, reuse the byte array.
func PadLeft ¶
PadLeft pad str to width, with padding rune at left. If str len already equals with or larger than width, return original str.
func PadRight ¶
PadRight pad str to width, with padding rune at right. If str len already equals with or larger than width, return original str.
func PadToCenter ¶ added in v1.3.1
PadToCenter pad str to width, with padding rune at left and right. If str len already equals with or larger than width, return original str.
func PrependIfMissing ¶
PrependIfMissing return a str start with suffix appended if not has the prefix; otherwise return str it's self
func PrependIfNotEmpty ¶ added in v1.3.0
PrependIfNotEmpty return str with prefix if str is not empty; return the origin str otherwise.
func Slice ¶ added in v1.7.0
Slice return substring from begin index(inclusive) to end index(exclusive). The index for slice can be negative, which means count from end of the string(calculated by str_len + index).
func SliceToEnd ¶ added in v1.7.0
SliceToEnd return substring from begin index(inclusive) to end of string. The index for slice can be negative, which means count from end of the string(calculated by str_len + index).
func SnakeToCamel ¶ added in v1.4.0
SnakeToCamel convert underscore style ascii str to Camel. The param capitalized determine if first char is converted to uppercase.
func SubstringAfter ¶
SubstringAfter return sub string after the sep. If str does not contains sep, return empty str.
func SubstringAfterLast ¶
SubstringAfterLast return sub string after the last sep. If str does not contains sep, return empty str.
func SubstringBefore ¶
SubstringBefore return sub string after the sep. If str does not contains sep, return the original str.
func SubstringBeforeLast ¶
SubstringBeforeLast return sub string after the last sep. If str does not contains sep, return the original str.
Types ¶
type JoinBuffer ¶ added in v1.5.0
type JoinBuffer struct {
// contains filtered or unexported fields
}
JoinBuffer is a tool to join string with prefix, suffix, and delimiter.
Usage:
joiner := &JoinBuffer{Separator:",", Prefix:"[", Suffix:"]"} joiner.Add(str) s := joiner.String()
func (*JoinBuffer) Add ¶ added in v1.5.0
func (j *JoinBuffer) Add(str string) *JoinBuffer
Add adds a new string item to JoinBuffer
func (*JoinBuffer) AddAll ¶ added in v1.5.0
func (j *JoinBuffer) AddAll(ss ...string) *JoinBuffer
AddAll add all strings to JoinBuffer
func (*JoinBuffer) AddAllAny ¶ added in v1.5.0
func (j *JoinBuffer) AddAllAny(ss ...interface{}) *JoinBuffer
AddAllAny add all values as string to JoinBuffer
func (*JoinBuffer) AddAllStringer ¶ added in v1.5.0
func (j *JoinBuffer) AddAllStringer(ss ...fmt.Stringer) *JoinBuffer
AddAllStringer add all Stringer's string value to JoinBuffer
func (*JoinBuffer) AddAny ¶ added in v1.5.0
func (j *JoinBuffer) AddAny(value interface{}) *JoinBuffer
AddAny add a new value of any type item to JoinBuffer
func (*JoinBuffer) AddBytes ¶ added in v1.5.0
func (j *JoinBuffer) AddBytes(data []byte) *JoinBuffer
AddBytes add new data item to JoinBuffer. The binary data is treated as utf-8 encoded string.
func (*JoinBuffer) AddInt ¶ added in v1.5.0
func (j *JoinBuffer) AddInt(value int) *JoinBuffer
AddInt add a new int item to JoinBuffer
func (*JoinBuffer) AddInt64 ¶ added in v1.5.0
func (j *JoinBuffer) AddInt64(value int64) *JoinBuffer
AddInt64 add a new int64 item to JoinBuffer
func (*JoinBuffer) AddStringer ¶ added in v1.5.0
func (j *JoinBuffer) AddStringer(value fmt.Stringer) *JoinBuffer
AddStringer add a new stringer item to JoinBuffer
func (*JoinBuffer) AddUint ¶ added in v1.5.0
func (j *JoinBuffer) AddUint(value uint) *JoinBuffer
AddUint add a new uint item to JoinBuffer
func (*JoinBuffer) AddUint64 ¶ added in v1.5.0
func (j *JoinBuffer) AddUint64(value uint64) *JoinBuffer
AddUint64 add a new uint64 item to JoinBuffer
func (*JoinBuffer) Reset ¶ added in v1.5.0
func (j *JoinBuffer) Reset() *JoinBuffer
Reset resets the JoinBuffer to be empty, can be reused.
func (*JoinBuffer) String ¶ added in v1.5.0
func (j *JoinBuffer) String() string
String join all values as string
type Joiner ¶
type Joiner struct { Prefix string // the prefix of joined string result Suffix string // the suffix of joined string result Separator string // the delimiter to join str OmitNil bool // if skip nil value OmitEmpty bool // if skip empty string NilToEmpty bool // if trans nil value to empty string }
Joiner contains join config for joining string. This struct does not have internal state, hence can be reused.
func (*Joiner) JoinStringer ¶ added in v1.5.0
JoinStringer join fmt.Stringer items to one string
func (*Joiner) NewBuffer ¶ added in v1.5.0
func (j *Joiner) NewBuffer() *JoinBuffer
NewBuffer create and return one new JoinBuffer for join string using the Joiner
type Splitter ¶ added in v1.2.1
type Splitter struct { Prefix string // the prefix of string to remove Suffix string // the suffix of string to remove Separator string // the delimiter to split str }
Splitter is a tool to split string with prefix, suffix, and separator into pieces.
Usage:
splitter := &Splitter{Separator:",", Prefix:"[", Suffix:"]"} ss := splitter.Split(str)