summaryrefslogtreecommitdiff
path: root/src/pkg/strconv
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/strconv')
-rw-r--r--src/pkg/strconv/atob_test.go34
-rw-r--r--src/pkg/strconv/atof.go11
-rw-r--r--src/pkg/strconv/atoi.go8
-rw-r--r--src/pkg/strconv/isprint.go4
-rw-r--r--src/pkg/strconv/makeisprint.go3
-rw-r--r--src/pkg/strconv/quote.go3
-rw-r--r--src/pkg/strconv/quote_example_test.go35
-rw-r--r--src/pkg/strconv/quote_test.go1
8 files changed, 84 insertions, 15 deletions
diff --git a/src/pkg/strconv/atob_test.go b/src/pkg/strconv/atob_test.go
index a7c1454eb..28f469f58 100644
--- a/src/pkg/strconv/atob_test.go
+++ b/src/pkg/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/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go
index 1b3f8fb33..286206481 100644
--- a/src/pkg/strconv/atof.go
+++ b/src/pkg/strconv/atof.go
@@ -353,17 +353,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/src/pkg/strconv/atoi.go b/src/pkg/strconv/atoi.go
index 2d0db7155..cbf0380ec 100644
--- a/src/pkg/strconv/atoi.go
+++ b/src/pkg/strconv/atoi.go
@@ -142,9 +142,11 @@ Error:
//
// The errors that ParseInt returns have concrete type *NumError
// and include err.Num = s. If s is empty or contains invalid
-// digits, err.Err = ErrSyntax; if the value corresponding
-// to s cannot be represented by a signed integer of the
-// given size, err.Err = ErrRange.
+// digits, err.Err = ErrSyntax and the returned value is 0;
+// if the value corresponding to s cannot be represented by a
+// signed integer of the given size, err.Err = ErrRange and the
+// returned value is the maximum magnitude integer of the
+// appropriate bitSize and sign.
func ParseInt(s string, base int, bitSize int) (i int64, err error) {
const fnParseInt = "ParseInt"
diff --git a/src/pkg/strconv/isprint.go b/src/pkg/strconv/isprint.go
index db5f0fbae..91f179535 100644
--- a/src/pkg/strconv/isprint.go
+++ b/src/pkg/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/src/pkg/strconv/makeisprint.go b/src/pkg/strconv/makeisprint.go
index 8a6699bdb..216159cc0 100644
--- a/src/pkg/strconv/makeisprint.go
+++ b/src/pkg/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/src/pkg/strconv/quote.go b/src/pkg/strconv/quote.go
index 7d6cdcf0b..aded7e593 100644
--- a/src/pkg/strconv/quote.go
+++ b/src/pkg/strconv/quote.go
@@ -144,7 +144,8 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte {
// characters other than space and tab.
func CanBackquote(s string) bool {
for i := 0; i < len(s); i++ {
- if (s[i] < ' ' && s[i] != '\t') || s[i] == '`' {
+ c := s[i]
+ if (c < ' ' && c != '\t') || c == '`' || c == '\u007F' {
return false
}
}
diff --git a/src/pkg/strconv/quote_example_test.go b/src/pkg/strconv/quote_example_test.go
new file mode 100644
index 000000000..405a57eb5
--- /dev/null
+++ b/src/pkg/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'") = é
+}
diff --git a/src/pkg/strconv/quote_test.go b/src/pkg/strconv/quote_test.go
index 61d9bf9a5..e4b5b6b9f 100644
--- a/src/pkg/strconv/quote_test.go
+++ b/src/pkg/strconv/quote_test.go
@@ -140,6 +140,7 @@ var canbackquotetests = []canBackquoteTest{
{string(29), false},
{string(30), false},
{string(31), false},
+ {string(0x7F), false},
{`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true},
{`0123456789`, true},
{`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true},