File: strbool.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 836 kB
  • sloc: makefile: 4
file content (25 lines) | stat: -rw-r--r-- 374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
}