Initial import
This commit is contained in:
25
strings.go
Normal file
25
strings.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package commons
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var whitespace = regexp.MustCompile(`\s+`)
|
||||
|
||||
// StringNormalize will replace arbitrary lengths of consecutive white space with a single one.
|
||||
func StringNormalize(s string) string {
|
||||
s = whitespace.ReplaceAllString(s, " ")
|
||||
|
||||
return strings.TrimSpace(s)
|
||||
}
|
||||
|
||||
//StringIsBlank checks if a string is blank. Will trim the string before the check takes place.
|
||||
func StringIsBlank(s string) bool {
|
||||
return len(strings.TrimSpace(s)) == 0
|
||||
}
|
||||
|
||||
// StringIsNotBlank check if a string is NOT blank.
|
||||
func StringIsNotBlank(s string) bool {
|
||||
return !StringIsBlank(s)
|
||||
}
|
||||
Reference in New Issue
Block a user