mirror of
https://github.com/golang/go
synced 2024-11-06 01:46:12 -07:00
351c15f1ce
Named returned values should only be used on public funcs and methods when it contributes to the documentation. Named return values should not be used if they're only saving the programmer a few lines of code inside the body of the function, especially if that means there's stutter in the documentation or it was only there so the programmer could use a naked return statement. (Naked returns should not be used except in very small functions) This change is a manual audit & cleanup of public func signatures. Signatures were not changed if: * the func was private (wouldn't be in public godoc) * the documentation referenced it * the named return value was an interesting name. (i.e. it wasn't simply stutter, repeating the name of the type) There should be no changes in behavior. (At least: none intended) Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109 Reviewed-on: https://go-review.googlesource.com/20024 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
36 lines
973 B
Go
36 lines
973 B
Go
// 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, syntaxError("ParseBool", str)
|
|
}
|
|
|
|
// FormatBool returns "true" or "false" according to the value of b
|
|
func FormatBool(b bool) string {
|
|
if b {
|
|
return "true"
|
|
}
|
|
return "false"
|
|
}
|
|
|
|
// AppendBool appends "true" or "false", according to the value of b,
|
|
// to dst and returns the extended buffer.
|
|
func AppendBool(dst []byte, b bool) []byte {
|
|
if b {
|
|
return append(dst, "true"...)
|
|
}
|
|
return append(dst, "false"...)
|
|
}
|