github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/internal/util/bool.go (about)

     1  package util
     2  
     3  import "strings"
     4  
     5  func ParseBool(s string) (b, ok bool) {
     6  	if len(s) == 0 {
     7  		return false, false
     8  	}
     9  	if s[0] == '0' {
    10  		return false, true
    11  	}
    12  	if '1' <= s[0] && s[0] <= '9' {
    13  		return true, true
    14  	}
    15  	switch strings.ToLower(s) {
    16  	case "true", "yes", "on":
    17  		return true, true
    18  	case "false", "no", "off":
    19  		return false, true
    20  	}
    21  	return false, false
    22  }