atob.go 983 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package strconv
  5. // ParseBool returns the boolean value represented by the string.
  6. // It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
  7. // Any other value returns an error.
  8. func ParseBool(str string) (value bool, err error) {
  9. switch str {
  10. case "1", "t", "T", "true", "TRUE", "True":
  11. return true, nil
  12. case "0", "f", "F", "false", "FALSE", "False":
  13. return false, nil
  14. }
  15. return false, syntaxError("ParseBool", str)
  16. }
  17. // FormatBool returns "true" or "false" according to the value of b
  18. func FormatBool(b bool) string {
  19. if b {
  20. return "true"
  21. }
  22. return "false"
  23. }
  24. // AppendBool appends "true" or "false", according to the value of b,
  25. // to dst and returns the extended buffer.
  26. func AppendBool(dst []byte, b bool) []byte {
  27. if b {
  28. return append(dst, "true"...)
  29. }
  30. return append(dst, "false"...)
  31. }