The Go Programming Language

Source file src/pkg/strconv/atob.go

     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	
     5	package strconv
     6	
     7	import "os"
     8	
     9	// Atob returns the boolean value represented by the string.
    10	// It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
    11	// Any other value returns an error.
    12	func Atob(str string) (value bool, err os.Error) {
    13		switch str {
    14		case "1", "t", "T", "true", "TRUE", "True":
    15			return true, nil
    16		case "0", "f", "F", "false", "FALSE", "False":
    17			return false, nil
    18		}
    19		return false, &NumError{str, os.EINVAL}
    20	}
    21	
    22	// Btoa returns "true" or "false" according to the value of the boolean argument
    23	func Btoa(b bool) string {
    24		if b {
    25			return "true"
    26		}
    27		return "false"
    28	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.