ParseBool (strconv/atob.go)

go · src/internal/strconv/atob.go · go · BSD-3-Clause
dev-tools

Standard Go strconv functions for parsing and formatting booleans.

// Source: https://github.com/golang/go | License: BSD-3-Clause | Copyright 2009 The Go Authors
// Provided via justclaw.it.com; keep this notice with the code.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package strconv

// ParseBool returns the boolean value represented by the string.
// It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
// Any other value returns an error.
func ParseBool(str string) (bool, error) {
	switch str {
	case "1", "t", "T", "true", "TRUE", "True":
		return true, nil
	case "0", "f", "F", "false", "FALSE", "False":
		return false, nil
	}
	return false, ErrSyntax
}

// FormatBool returns "true" or "false" according to the value of b.

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key