Documentation ¶
Index ¶
- func AppendIfMissing(str string, suffix string) string
- func AppendIfNotEmpty(str string, suffix string) string
- func AsBytes(str string) []byte
- 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, others ...string) 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 ValueOf(v interface{}) string
- func WrapBytes(bytes []byte) 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
- type SubStringResult
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 ¶
AppendIfNotEmpty return str with suffix if str is not empty; return the origin str otherwise.
func AsBytes ¶
AsBytes unsafe convert string to byte slice. This function do not allocate new buffer, reuse the string buffer.
func CamelToSnake ¶
CamelToSnake convert camel style ascii str to underscore snake style.
func Capitalize ¶
Capitalize return str with first char of ascii str upper case.
func ContainsAny ¶
ContainsAny return whether str contains any one of subStrings.
func Copy ¶
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 ¶
DeCapitalize return str with first char of ascii str lower case.
func FirstNonEmpty ¶
FirstNonEmpty return first non-empty string; If all string is empty, return empty string.
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 ¶
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 ¶
PrependIfNotEmpty return str with prefix if str is not empty; return the origin str otherwise.
func Slice ¶
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 ¶
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 ¶
SnakeToCamel convert underscore style ascii str to Camel. The param capitalized determine if first char is converted to uppercase.
Types ¶
type JoinBuffer ¶
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 ¶
func (j *JoinBuffer) Add(str string) *JoinBuffer
Add adds a new string item to JoinBuffer
func (*JoinBuffer) AddAll ¶
func (j *JoinBuffer) AddAll(ss ...string) *JoinBuffer
AddAll add all strings to JoinBuffer
func (*JoinBuffer) AddAllAny ¶
func (j *JoinBuffer) AddAllAny(ss ...interface{}) *JoinBuffer
AddAllAny add all values as string to JoinBuffer
func (*JoinBuffer) AddAllStringer ¶
func (j *JoinBuffer) AddAllStringer(ss ...fmt.Stringer) *JoinBuffer
AddAllStringer add all Stringer's string value to JoinBuffer
func (*JoinBuffer) AddAny ¶
func (j *JoinBuffer) AddAny(value interface{}) *JoinBuffer
AddAny add a new value of any type item to JoinBuffer
func (*JoinBuffer) AddBytes ¶
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 ¶
func (j *JoinBuffer) AddInt(value int) *JoinBuffer
AddInt add a new int item to JoinBuffer
func (*JoinBuffer) AddInt64 ¶
func (j *JoinBuffer) AddInt64(value int64) *JoinBuffer
AddInt64 add a new int64 item to JoinBuffer
func (*JoinBuffer) AddStringer ¶
func (j *JoinBuffer) AddStringer(value fmt.Stringer) *JoinBuffer
AddStringer add a new stringer item to JoinBuffer
func (*JoinBuffer) AddUint ¶
func (j *JoinBuffer) AddUint(value uint) *JoinBuffer
AddUint add a new uint item to JoinBuffer
func (*JoinBuffer) AddUint64 ¶
func (j *JoinBuffer) AddUint64(value uint64) *JoinBuffer
AddUint64 add a new uint64 item to JoinBuffer
func (*JoinBuffer) Reset ¶
func (j *JoinBuffer) Reset() *JoinBuffer
Reset resets the JoinBuffer to be empty, can be reused.
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 ¶
JoinStringer join fmt.Stringer items to one string
func (*Joiner) NewBuffer ¶
func (j *Joiner) NewBuffer() *JoinBuffer
NewBuffer create and return one new JoinBuffer for join string using the Joiner
type Splitter ¶
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)
type SubStringResult ¶
type SubStringResult struct {
// contains filtered or unexported fields
}
SubStringResult is a result holder for SubstringAfter/SubstringAfterLast/SubstringBefore/SubstringBeforeLast methods.
func SubstringAfter ¶
func SubstringAfter(str string, sep string) SubStringResult
SubstringAfter return sub string after the sep. If str does not contain sep, return empty str.
func SubstringAfterLast ¶
func SubstringAfterLast(str string, sep string) SubStringResult
SubstringAfterLast return sub string after the last sep. If str does not contain sep, return empty str.
func SubstringBefore ¶
func SubstringBefore(str string, sep string) SubStringResult
SubstringBefore return sub string after the sep. If str does not contain sep, return the original str.
func SubstringBeforeLast ¶
func SubstringBeforeLast(str string, sep string) SubStringResult
SubstringBeforeLast return sub string after the last sep. If str does not contain sep, return the original str.
func (SubStringResult) Else ¶
func (r SubStringResult) Else(fallback string) string
Else return the substring result; if substring does not exist, return fallback str.
func (SubStringResult) ElseEmpty ¶
func (r SubStringResult) ElseEmpty() string
ElseEmpty return the substring result; if substring does not exist, return empty str.
func (SubStringResult) ElseOriginal ¶
func (r SubStringResult) ElseOriginal() string
ElseOriginal return the substring result; if substring does not exist, return original str.