status-go/vendor/github.com/anacrolix/missinggo/v2/strbool.go

26 lines
374 B
Go
Raw Normal View History

2022-03-10 09:44:48 +00:00
package missinggo
import (
"strconv"
"strings"
"unicode"
)
func StringTruth(s string) (ret bool) {
s = strings.TrimFunc(s, func(r rune) bool {
return r == 0 || unicode.IsSpace(r)
})
if s == "" {
return false
}
ret, err := strconv.ParseBool(s)
if err == nil {
return
}
i, err := strconv.ParseInt(s, 0, 0)
if err == nil {
return i != 0
}
return true
}