- reimplement TrimBlanChar

This commit is contained in:
gazebo
2018-10-31 11:48:49 +08:00
parent e9d0a172ee
commit a69e005e31
3 changed files with 36 additions and 4 deletions

View File

@@ -196,10 +196,7 @@ func FilterMb4(content string) string {
}
func TrimBlanChar(str string) string {
return strings.TrimFunc(str, func(value rune) bool {
strValue := string(value)
return strValue == " " || strValue == "\t" || strValue == "\n" || strValue == "\r"
})
return strings.Trim(str, "\n\r\t ")
}
func RemoveGeneralMapKeys(obj map[string]interface{}, keys ...string) map[string]interface{} {

View File

@@ -125,3 +125,12 @@ func TestRemoveGeneralMapKeys(t *testing.T) {
t.Fatal("RemoveGeneralMapKeys handle nil wrong")
}
}
func TestTrimBlanChar(t *testing.T) {
str := `
大小21
`
if TrimBlanChar(str) != "大小21" {
t.Fatal("TrimBlanChar doesn't work")
}
}