schema: improve errors, disallow dangling spaces.
This commit is contained in:
25
schema/helpers.go
Normal file
25
schema/helpers.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// isTrimmed checks if strings.TrimSpace(v) == v, i.e. that the value doesn't have dangling spaces
|
||||
func isTrimmed(s string) bool {
|
||||
if len(s) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
first, _ := utf8.DecodeRuneInString(s)
|
||||
if unicode.IsSpace(first) {
|
||||
return false
|
||||
}
|
||||
|
||||
last, _ := utf8.DecodeLastRuneInString(s)
|
||||
if unicode.IsSpace(last) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user