diff options
author | Ian Lance Taylor <iant@google.com> | 2014-06-04 23:15:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-04 23:15:33 +0000 |
commit | bae90c989cb020d17a24919ec84c0b8dd2fae2da (patch) | |
tree | 89766166feb4ceca2d983169c5360e3f6f521b12 /libgo/go/strconv | |
parent | 82b3da6a714493644a4333bfd8205e3341ed3b8e (diff) | |
download | gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.zip gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.gz gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.bz2 |
libgo: Merge from revision 18783:00cce3a34d7e of master library.
This revision was committed January 7, 2014. The next
revision deleted runtime/mfinal.c. That will be done in a
subsequent merge.
This merge changes type descriptors to add a zero field,
pointing to a zero value for that type. This is implemented
as a common variable.
* go-gcc.cc (Gcc_backend::implicit_variable): Add is_common and
alignment parameters. Permit init parameter to be NULL.
From-SVN: r211249
Diffstat (limited to 'libgo/go/strconv')
-rw-r--r-- | libgo/go/strconv/atob_test.go | 34 | ||||
-rw-r--r-- | libgo/go/strconv/atof.go | 11 | ||||
-rw-r--r-- | libgo/go/strconv/isprint.go | 4 | ||||
-rw-r--r-- | libgo/go/strconv/makeisprint.go | 3 | ||||
-rw-r--r-- | libgo/go/strconv/quote_example_test.go | 35 |
5 files changed, 76 insertions, 11 deletions
diff --git a/libgo/go/strconv/atob_test.go b/libgo/go/strconv/atob_test.go index a7c1454..28f469f 100644 --- a/libgo/go/strconv/atob_test.go +++ b/libgo/go/strconv/atob_test.go @@ -5,6 +5,7 @@ package strconv_test import ( + "bytes" . "strconv" "testing" ) @@ -55,3 +56,36 @@ func TestParseBool(t *testing.T) { } } } + +var boolString = map[bool]string{ + true: "true", + false: "false", +} + +func TestFormatBool(t *testing.T) { + for b, s := range boolString { + if f := FormatBool(b); f != s { + t.Errorf(`FormatBool(%v): expected %q but got %q`, b, s, f) + } + } +} + +type appendBoolTest struct { + b bool + in []byte + out []byte +} + +var appendBoolTests = []appendBoolTest{ + {true, []byte("foo "), []byte("foo true")}, + {false, []byte("foo "), []byte("foo false")}, +} + +func TestAppendBool(t *testing.T) { + for _, test := range appendBoolTests { + b := AppendBool(test.in, test.b) + if !bytes.Equal(b, test.out) { + t.Errorf("AppendBool(%q, %v): expected %q but got %q", test.in, test.b, test.out, b) + } + } +} diff --git a/libgo/go/strconv/atof.go b/libgo/go/strconv/atof.go index 1dc521f..beaa68d 100644 --- a/libgo/go/strconv/atof.go +++ b/libgo/go/strconv/atof.go @@ -354,17 +354,6 @@ out: return bits, overflow } -func (d *decimal) atof32int() float32 { - f := float32(0) - for i := 0; i < d.nd; i++ { - f = f*10 + float32(d.d[i]-'0') - } - if d.neg { - f = -f - } - return f -} - // Exact powers of 10. var float64pow10 = []float64{ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, diff --git a/libgo/go/strconv/isprint.go b/libgo/go/strconv/isprint.go index db5f0fb..91f1795 100644 --- a/libgo/go/strconv/isprint.go +++ b/libgo/go/strconv/isprint.go @@ -1,3 +1,7 @@ +// Copyright 2013 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. + // DO NOT EDIT. GENERATED BY // go run makeisprint.go >x && mv x isprint.go diff --git a/libgo/go/strconv/makeisprint.go b/libgo/go/strconv/makeisprint.go index 8a6699b..216159c 100644 --- a/libgo/go/strconv/makeisprint.go +++ b/libgo/go/strconv/makeisprint.go @@ -122,6 +122,9 @@ func main() { } } + fmt.Printf(`// Copyright 2013 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.` + "\n\n") fmt.Printf("// DO NOT EDIT. GENERATED BY\n") fmt.Printf("// go run makeisprint.go >x && mv x isprint.go\n\n") fmt.Printf("package strconv\n\n") diff --git a/libgo/go/strconv/quote_example_test.go b/libgo/go/strconv/quote_example_test.go new file mode 100644 index 0000000..405a57e --- /dev/null +++ b/libgo/go/strconv/quote_example_test.go @@ -0,0 +1,35 @@ +// Copyright 2013 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_test + +import ( + "fmt" + "strconv" +) + +func ExampleUnquote() { + test := func(s string) { + t, err := strconv.Unquote(s) + if err != nil { + fmt.Printf("Unquote(%#v): %v\n", s, err) + } else { + fmt.Printf("Unquote(%#v) = %v\n", s, t) + } + } + + s := `cafe\u0301` + // If the string doesn't have quotes, it can't be unquoted. + test(s) // invalid syntax + test("`" + s + "`") + test(`"` + s + `"`) + + test(`'\u00e9'`) + + // Output: + // Unquote("cafe\\u0301"): invalid syntax + // Unquote("`cafe\\u0301`") = cafe\u0301 + // Unquote("\"cafe\\u0301\"") = café + // Unquote("'\\u00e9'") = é +} |