// Package strutil provide some string,char,byte util functions
package strutilimport ()// OrCond return s1 on cond is True, OR return s2.// Like: cond ? s1 : s2func ( bool, , string) string {if {return }return}// BlankOr return default value on val is blank, otherwise return valfunc (, string) string { = strings.TrimSpace()if != "" {return }return}// ZeroOr return default value on val is zero, otherwise return val. same of OrElse()func [ ~string](, ) {if != "" {return }return}// ErrorOr return default value on err is not nil, otherwise return s// func ErrorOr(s string, err error, defVal string) string {// if err != nil {// return defVal// }// return s// }// OrElse return default value on s is empty, otherwise return sfunc (, string) string {if != "" {return }return}// OrElseNilSafe return default value on s is nil, otherwise return sfunc ( *string, string) string {if == nil || * == "" {return }return *}// OrHandle return fn(s) on s is not empty.func ( string, comdef.StringHandleFunc) string {if != "" {return () }return}// Valid return first not empty element.func ( ...string) string {for , := range {if != "" {return } }return""}// SubstrCount returns the number of times the substr substring occurs in the s string.// Actually, it comes from strings.Count().//// - s The string to search in// - substr The substring to search for// - params[0] The offset where to start counting.// - params[1] The maximum length after the specified offset to search for the substring.func (, string, ...uint64) (int, error) { := len() := != 0if && > 2 {return0, errors.New("too many parameters") }if ! {returnstrings.Count(, ), nil } := len() := 0 := if { = int([0])if == 2 { := int([1]) = + }if > { = } } = string([]rune()[:])returnstrings.Count(, ), nil}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.