summaryrefslogtreecommitdiff
path: root/src/pkg/strconv
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-07 11:55:06 -0700
committerRuss Cox <rsc@golang.org>2009-10-07 11:55:06 -0700
commit2b77e59eaed6d039951b5ef7ad1f3db421962dc2 (patch)
tree10feec844f56ec9dce304804c581d9c5209e74c1 /src/pkg/strconv
parent5843e5da3dca981d5b2522a3be91bd1426c71d26 (diff)
downloadgolang-2b77e59eaed6d039951b5ef7ad1f3db421962dc2.tar.gz
apply gofmt to rand reflect regexp rpc runtime sort strconv strings sync syscall testing time unicode unsafe utf8
R=gri DELTA=1409 (79 added, 24 deleted, 1306 changed) OCL=35415 CL=35437
Diffstat (limited to 'src/pkg/strconv')
-rw-r--r--src/pkg/strconv/atof.go39
-rw-r--r--src/pkg/strconv/atof_test.go124
-rw-r--r--src/pkg/strconv/atoi.go56
-rw-r--r--src/pkg/strconv/atoi_test.go91
-rw-r--r--src/pkg/strconv/decimal_test.go95
-rw-r--r--src/pkg/strconv/fp_test.go7
-rw-r--r--src/pkg/strconv/ftoa_test.go168
-rw-r--r--src/pkg/strconv/internal_test.go1
-rw-r--r--src/pkg/strconv/itoa.go6
-rw-r--r--src/pkg/strconv/itoa_test.go110
-rw-r--r--src/pkg/strconv/quote.go32
-rw-r--r--src/pkg/strconv/quote_test.go176
12 files changed, 451 insertions, 454 deletions
diff --git a/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go
index 137955809..3b0562391 100644
--- a/src/pkg/strconv/atof.go
+++ b/src/pkg/strconv/atof.go
@@ -107,9 +107,7 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
}
// decimal power of ten to binary power of two.
-var powtab = []int{
- 1, 3, 6, 9, 13, 16, 19, 23, 26
-}
+var powtab = []int{1, 3, 6, 9, 13, 16, 19, 23, 26}
func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uint64, overflow bool) {
var exp int;
@@ -164,30 +162,30 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
// Minimum representable exponent is flt.bias+1.
// If the exponent is smaller, move it up and
// adjust d accordingly.
- if exp < flt.bias+1 {
- n := flt.bias+1 - exp;
+ if exp < flt.bias + 1 {
+ n := flt.bias + 1 - exp;
d.Shift(-n);
exp += n;
}
- if exp-flt.bias >= 1<<flt.expbits - 1 {
+ if exp - flt.bias >= 1 << flt.expbits - 1 {
goto overflow;
}
// Extract 1+flt.mantbits bits.
- mant = d.Shift(int(1+flt.mantbits)).RoundedInteger();
+ mant = d.Shift(int(1 + flt.mantbits)).RoundedInteger();
// Rounding might have added a bit; shift down.
- if mant == 2<<flt.mantbits {
+ if mant == 2 << flt.mantbits {
mant >>= 1;
exp++;
- if exp-flt.bias >= 1<<flt.expbits - 1 {
+ if exp - flt.bias >= 1 << flt.expbits - 1 {
goto overflow;
}
}
// Denormalized?
- if mant&(1<<flt.mantbits) == 0 {
+ if mant&(1 << flt.mantbits) == 0 {
exp = flt.bias;
}
goto out;
@@ -195,15 +193,15 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
overflow:
// ±Inf
mant = 0;
- exp = 1<<flt.expbits - 1 + flt.bias;
+ exp = 1 << flt.expbits - 1 + flt.bias;
overflow = true;
out:
// Assemble bits.
- bits := mant & (uint64(1)<<flt.mantbits - 1);
- bits |= uint64((exp-flt.bias)&(1<<flt.expbits - 1)) << flt.mantbits;
+ bits := mant&(uint64(1) << flt.mantbits - 1);
+ bits |= uint64((exp - flt.bias)&(1 << flt.expbits - 1)) << flt.mantbits;
if neg {
- bits |= 1<<flt.mantbits<<flt.expbits;
+ bits |= 1 << flt.mantbits << flt.expbits;
}
return bits, overflow;
}
@@ -233,14 +231,12 @@ func decimalAtof32Int(neg bool, d *decimal) float32 {
}
// Exact powers of 10.
-var float64pow10 = []float64 {
+var float64pow10 = []float64{
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
- 1e20, 1e21, 1e22
-}
-var float32pow10 = []float32 {
- 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10
+ 1e20, 1e21, 1e22,
}
+var float32pow10 = []float32{1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10}
// If possible to convert decimal d to 64-bit float f exactly,
// entirely in floating-point math, do so, avoiding the expense of decimalToFloatBits.
@@ -338,7 +334,7 @@ func Atof32(s string) (f float32, err os.Error) {
if ovf {
err = &NumError{s, os.ERANGE};
}
- return f, err
+ return f, err;
}
// Atof64 converts the string s to a 64-bit floating-point number.
@@ -359,7 +355,7 @@ func Atof64(s string) (f float64, err os.Error) {
if ovf {
err = &NumError{s, os.ERANGE};
}
- return f, err
+ return f, err;
}
// Atof is like Atof32 or Atof64, depending on the size of float.
@@ -371,4 +367,3 @@ func Atof(s string) (f float, err os.Error) {
f1, err1 := Atof64(s);
return float(f1), err1;
}
-
diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go
index a2894fc75..c0779d361 100644
--- a/src/pkg/strconv/atof_test.go
+++ b/src/pkg/strconv/atof_test.go
@@ -5,91 +5,91 @@
package strconv_test
import (
- "os";
- "reflect";
- . "strconv";
- "testing";
+ "os";
+ "reflect";
+ . "strconv";
+ "testing";
)
type atofTest struct {
- in string;
- out string;
- err os.Error;
+ in string;
+ out string;
+ err os.Error;
}
-var atoftests = []atofTest {
- atofTest{ "", "0", os.EINVAL },
- atofTest{ "1", "1", nil },
- atofTest{ "+1", "1", nil },
- atofTest{ "1x", "0", os.EINVAL },
- atofTest{ "1.1.", "0", os.EINVAL },
- atofTest{ "1e23", "1e+23", nil },
- atofTest{ "100000000000000000000000", "1e+23", nil },
- atofTest{ "1e-100", "1e-100", nil },
- atofTest{ "123456700", "1.234567e+08", nil },
- atofTest{ "99999999999999974834176", "9.999999999999997e+22", nil },
- atofTest{ "100000000000000000000001", "1.0000000000000001e+23", nil },
- atofTest{ "100000000000000008388608", "1.0000000000000001e+23", nil },
- atofTest{ "100000000000000016777215", "1.0000000000000001e+23", nil },
- atofTest{ "100000000000000016777216", "1.0000000000000003e+23", nil },
- atofTest{ "-1", "-1", nil },
- atofTest{ "-0", "-0", nil },
- atofTest{ "1e-20", "1e-20", nil },
- atofTest{ "625e-3", "0.625", nil },
+var atoftests = []atofTest{
+ atofTest{"", "0", os.EINVAL},
+ atofTest{"1", "1", nil},
+ atofTest{"+1", "1", nil},
+ atofTest{"1x", "0", os.EINVAL},
+ atofTest{"1.1.", "0", os.EINVAL},
+ atofTest{"1e23", "1e+23", nil},
+ atofTest{"100000000000000000000000", "1e+23", nil},
+ atofTest{"1e-100", "1e-100", nil},
+ atofTest{"123456700", "1.234567e+08", nil},
+ atofTest{"99999999999999974834176", "9.999999999999997e+22", nil},
+ atofTest{"100000000000000000000001", "1.0000000000000001e+23", nil},
+ atofTest{"100000000000000008388608", "1.0000000000000001e+23", nil},
+ atofTest{"100000000000000016777215", "1.0000000000000001e+23", nil},
+ atofTest{"100000000000000016777216", "1.0000000000000003e+23", nil},
+ atofTest{"-1", "-1", nil},
+ atofTest{"-0", "-0", nil},
+ atofTest{"1e-20", "1e-20", nil},
+ atofTest{"625e-3", "0.625", nil},
// largest float64
- atofTest{ "1.7976931348623157e308", "1.7976931348623157e+308", nil },
- atofTest{ "-1.7976931348623157e308", "-1.7976931348623157e+308", nil },
+ atofTest{"1.7976931348623157e308", "1.7976931348623157e+308", nil},
+ atofTest{"-1.7976931348623157e308", "-1.7976931348623157e+308", nil},
// next float64 - too large
- atofTest{ "1.7976931348623159e308", "+Inf", os.ERANGE },
- atofTest{ "-1.7976931348623159e308", "-Inf", os.ERANGE },
+ atofTest{"1.7976931348623159e308", "+Inf", os.ERANGE},
+ atofTest{"-1.7976931348623159e308", "-Inf", os.ERANGE},
// the border is ...158079
// borderline - okay
- atofTest{ "1.7976931348623158e308", "1.7976931348623157e+308", nil },
- atofTest{ "-1.7976931348623158e308", "-1.7976931348623157e+308", nil },
+ atofTest{"1.7976931348623158e308", "1.7976931348623157e+308", nil},
+ atofTest{"-1.7976931348623158e308", "-1.7976931348623157e+308", nil},
// borderline - too large
- atofTest{ "1.797693134862315808e308", "+Inf", os.ERANGE },
- atofTest{ "-1.797693134862315808e308", "-Inf", os.ERANGE },
+ atofTest{"1.797693134862315808e308", "+Inf", os.ERANGE},
+ atofTest{"-1.797693134862315808e308", "-Inf", os.ERANGE},
// a little too large
- atofTest{ "1e308", "1e+308", nil },
- atofTest{ "2e308", "+Inf", os.ERANGE },
- atofTest{ "1e309", "+Inf", os.ERANGE },
+ atofTest{"1e308", "1e+308", nil},
+ atofTest{"2e308", "+Inf", os.ERANGE},
+ atofTest{"1e309", "+Inf", os.ERANGE},
// way too large
- atofTest{ "1e310", "+Inf", os.ERANGE },
- atofTest{ "-1e310", "-Inf", os.ERANGE },
- atofTest{ "1e400", "+Inf", os.ERANGE },
- atofTest{ "-1e400", "-Inf", os.ERANGE },
- atofTest{ "1e400000", "+Inf", os.ERANGE },
- atofTest{ "-1e400000", "-Inf", os.ERANGE },
+ atofTest{"1e310", "+Inf", os.ERANGE},
+ atofTest{"-1e310", "-Inf", os.ERANGE},
+ atofTest{"1e400", "+Inf", os.ERANGE},
+ atofTest{"-1e400", "-Inf", os.ERANGE},
+ atofTest{"1e400000", "+Inf", os.ERANGE},
+ atofTest{"-1e400000", "-Inf", os.ERANGE},
// denormalized
- atofTest{ "1e-305", "1e-305", nil },
- atofTest{ "1e-306", "1e-306", nil },
- atofTest{ "1e-307", "1e-307", nil },
- atofTest{ "1e-308", "1e-308", nil },
- atofTest{ "1e-309", "1e-309", nil },
- atofTest{ "1e-310", "1e-310", nil },
- atofTest{ "1e-322", "1e-322", nil },
+ atofTest{"1e-305", "1e-305", nil},
+ atofTest{"1e-306", "1e-306", nil},
+ atofTest{"1e-307", "1e-307", nil},
+ atofTest{"1e-308", "1e-308", nil},
+ atofTest{"1e-309", "1e-309", nil},
+ atofTest{"1e-310", "1e-310", nil},
+ atofTest{"1e-322", "1e-322", nil},
// smallest denormal
- atofTest{ "5e-324", "5e-324", nil },
+ atofTest{"5e-324", "5e-324", nil},
// too small
- atofTest{ "4e-324", "0", nil },
+ atofTest{"4e-324", "0", nil},
// way too small
- atofTest{ "1e-350", "0", nil },
- atofTest{ "1e-400000", "0", nil },
+ atofTest{"1e-350", "0", nil},
+ atofTest{"1e-400000", "0", nil},
// try to overflow exponent
- atofTest{ "1e-4294967296", "0", nil },
- atofTest{ "1e+4294967296", "+Inf", os.ERANGE },
- atofTest{ "1e-18446744073709551616", "0", nil },
- atofTest{ "1e+18446744073709551616", "+Inf", os.ERANGE },
+ atofTest{"1e-4294967296", "0", nil},
+ atofTest{"1e+4294967296", "+Inf", os.ERANGE},
+ atofTest{"1e-18446744073709551616", "0", nil},
+ atofTest{"1e+18446744073709551616", "+Inf", os.ERANGE},
// Parse errors
- atofTest{ "1e", "0", os.EINVAL },
- atofTest{ "1e-", "0", os.EINVAL },
- atofTest{ ".e-1", "0", os.EINVAL },
+ atofTest{"1e", "0", os.EINVAL},
+ atofTest{"1e-", "0", os.EINVAL},
+ atofTest{".e-1", "0", os.EINVAL},
}
func init() {
@@ -98,7 +98,7 @@ func init() {
for i := range atoftests {
test := &atoftests[i];
if test.err != nil {
- test.err = &NumError{test.in, test.err}
+ test.err = &NumError{test.in, test.err};
}
}
}
diff --git a/src/pkg/strconv/atoi.go b/src/pkg/strconv/atoi.go
index d86d0f88b..f31632eff 100644
--- a/src/pkg/strconv/atoi.go
+++ b/src/pkg/strconv/atoi.go
@@ -7,8 +7,8 @@ package strconv
import "os"
type NumError struct {
- Num string;
- Error os.Error;
+ Num string;
+ Error os.Error;
}
func (e *NumError) String() string {
@@ -19,18 +19,19 @@ func (e *NumError) String() string {
func computeIntsize() uint {
siz := uint(8);
for 1<<siz != 0 {
- siz *= 2
+ siz *= 2;
}
- return siz
+ return siz;
}
-var IntSize = computeIntsize();
+
+var IntSize = computeIntsize()
// Return the first number n such that n*base >= 1<<64.
func cutoff64(base int) uint64 {
if base < 2 {
return 0;
}
- return (1<<64 - 1) / uint64(base) + 1;
+ return (1<<64 - 1)/uint64(base) + 1;
}
// Btoui64 interprets a string s in an arbitrary base b (2 to 36)
@@ -57,11 +58,11 @@ func Btoui64(s string, b int) (n uint64, err os.Error) {
var v byte;
switch {
case '0' <= s[i] && s[i] <= '9':
- v = s[i] - '0';
+ v = s[i]-'0';
case 'a' <= s[i] && s[i] <= 'z':
- v = s[i] - 'a' + 10;
+ v = s[i]-'a'+10;
case 'A' <= s[i] && s[i] <= 'Z':
- v = s[i] - 'A' + 10;
+ v = s[i]-'A'+10;
default:
n = 0;
err = os.EINVAL;
@@ -75,7 +76,7 @@ func Btoui64(s string, b int) (n uint64, err os.Error) {
if n >= cutoff {
// n*b overflows
- n = 1<<64-1;
+ n = 1<<64 - 1;
err = os.ERANGE;
goto Error;
}
@@ -84,7 +85,7 @@ func Btoui64(s string, b int) (n uint64, err os.Error) {
n1 := n+uint64(v);
if n1 < n {
// n+v overflows
- n = 1<<64-1;
+ n = 1<<64 - 1;
err = os.ERANGE;
goto Error;
}
@@ -107,7 +108,7 @@ Error:
func Atoui64(s string) (n uint64, err os.Error) {
// Empty string bad.
if len(s) == 0 {
- return 0, &NumError{s, os.EINVAL}
+ return 0, &NumError{s, os.EINVAL};
}
// Look for octal, hex prefix.
@@ -132,17 +133,17 @@ func Atoui64(s string) (n uint64, err os.Error) {
func Atoi64(s string) (i int64, err os.Error) {
// Empty string bad.
if len(s) == 0 {
- return 0, &NumError{s, os.EINVAL}
+ return 0, &NumError{s, os.EINVAL};
}
// Pick off leading sign.
s0 := s;
neg := false;
if s[0] == '+' {
- s = s[1:len(s)]
+ s = s[1:len(s)];
} else if s[0] == '-' {
neg = true;
- s = s[1:len(s)]
+ s = s[1:len(s)];
}
// Convert unsigned and check range.
@@ -150,47 +151,46 @@ func Atoi64(s string) (i int64, err os.Error) {
un, err = Atoui64(s);
if err != nil && err.(*NumError).Error != os.ERANGE {
err.(*NumError).Num = s0;
- return 0, err
+ return 0, err;
}
if !neg && un >= 1<<63 {
- return 1<<63-1, &NumError{s0, os.ERANGE}
+ return 1<<63 - 1, &NumError{s0, os.ERANGE};
}
if neg && un > 1<<63 {
- return -1<<63, &NumError{s0, os.ERANGE}
+ return -1 << 63, &NumError{s0, os.ERANGE};
}
n := int64(un);
if neg {
- n = -n
+ n = -n;
}
- return n, nil
+ return n, nil;
}
// Atoui is like Atoui64 but returns its result as a uint.
func Atoui(s string) (i uint, err os.Error) {
i1, e1 := Atoui64(s);
if e1 != nil && e1.(*NumError).Error != os.ERANGE {
- return 0, e1
+ return 0, e1;
}
i = uint(i1);
if uint64(i) != i1 {
- return ^uint(0), &NumError{s, os.ERANGE}
+ return ^uint(0), &NumError{s, os.ERANGE};
}
- return i, nil
+ return i, nil;
}
// Atoi is like Atoi64 but returns its result as an int.
func Atoi(s string) (i int, err os.Error) {
i1, e1 := Atoi64(s);
if e1 != nil && e1.(*NumError).Error != os.ERANGE {
- return 0, e1
+ return 0, e1;
}
i = int(i1);
if int64(i) != i1 {
if i1 < 0 {
- return -1<<(IntSize-1), &NumError{s, os.ERANGE}
+ return -1 << (IntSize-1), &NumError{s, os.ERANGE};
}
- return 1<<(IntSize-1) - 1, &NumError{s, os.ERANGE}
+ return 1<<(IntSize-1) - 1, &NumError{s, os.ERANGE};
}
- return i, nil
+ return i, nil;
}
-
diff --git a/src/pkg/strconv/atoi_test.go b/src/pkg/strconv/atoi_test.go
index 2632e572a..adbf7f5c3 100644
--- a/src/pkg/strconv/atoi_test.go
+++ b/src/pkg/strconv/atoi_test.go
@@ -5,19 +5,19 @@
package strconv_test
import (
- "os";
- "reflect";
- . "strconv";
- "testing";
+ "os";
+ "reflect";
+ . "strconv";
+ "testing";
)
type atoui64Test struct {
- in string;
- out uint64;
- err os.Error;
+ in string;
+ out uint64;
+ err os.Error;
}
-var atoui64tests = []atoui64Test {
+var atoui64tests = []atoui64Test{
atoui64Test{"", 0, os.EINVAL},
atoui64Test{"0", 0, nil},
atoui64Test{"1", 1, nil},
@@ -27,24 +27,24 @@ var atoui64tests = []atoui64Test {
atoui64Test{"0X12345", 0x12345, nil},
atoui64Test{"12345x", 0, os.EINVAL},
atoui64Test{"98765432100", 98765432100, nil},
- atoui64Test{"18446744073709551615", 1<<64-1, nil},
- atoui64Test{"18446744073709551616", 1<<64-1, os.ERANGE},
- atoui64Test{"18446744073709551620", 1<<64-1, os.ERANGE},
- atoui64Test{"0xFFFFFFFFFFFFFFFF", 1<<64-1, nil},
- atoui64Test{"0x10000000000000000", 1<<64-1, os.ERANGE},
- atoui64Test{"01777777777777777777777", 1<<64-1, nil},
+ atoui64Test{"18446744073709551615", 1<<64 - 1, nil},
+ atoui64Test{"18446744073709551616", 1<<64 - 1, os.ERANGE},
+ atoui64Test{"18446744073709551620", 1<<64 - 1, os.ERANGE},
+ atoui64Test{"0xFFFFFFFFFFFFFFFF", 1<<64 - 1, nil},
+ atoui64Test{"0x10000000000000000", 1<<64 - 1, os.ERANGE},
+ atoui64Test{"01777777777777777777777", 1<<64 - 1, nil},
atoui64Test{"01777777777777777777778", 0, os.EINVAL},
- atoui64Test{"02000000000000000000000", 1<<64-1, os.ERANGE},
+ atoui64Test{"02000000000000000000000", 1<<64 - 1, os.ERANGE},
atoui64Test{"0200000000000000000000", 1<<61, nil},
}
type atoi64Test struct {
- in string;
- out int64;
- err os.Error;
+ in string;
+ out int64;
+ err os.Error;
}
-var atoi64tests = []atoi64Test {
+var atoi64tests = []atoi64Test{
atoi64Test{"", 0, os.EINVAL},
atoi64Test{"0", 0, nil},
atoi64Test{"-0", 0, nil},
@@ -60,21 +60,21 @@ var atoi64tests = []atoi64Test {
atoi64Test{"-12345x", 0, os.EINVAL},
atoi64Test{"98765432100", 98765432100, nil},
atoi64Test{"-98765432100", -98765432100, nil},
- atoi64Test{"9223372036854775807", 1<<63-1, nil},
- atoi64Test{"-9223372036854775807", -(1<<63-1), nil},
- atoi64Test{"9223372036854775808", 1<<63-1, os.ERANGE},
- atoi64Test{"-9223372036854775808", -1<<63, nil},
- atoi64Test{"9223372036854775809", 1<<63-1, os.ERANGE},
- atoi64Test{"-9223372036854775809", -1<<63, os.ERANGE},
+ atoi64Test{"9223372036854775807", 1<<63 - 1, nil},
+ atoi64Test{"-9223372036854775807", -(1<<63 - 1), nil},
+ atoi64Test{"9223372036854775808", 1<<63 - 1, os.ERANGE},
+ atoi64Test{"-9223372036854775808", -1 << 63, nil},
+ atoi64Test{"9223372036854775809", 1<<63 - 1, os.ERANGE},
+ atoi64Test{"-9223372036854775809", -1 << 63, os.ERANGE},
}
type atoui32Test struct {
- in string;
- out uint32;
- err os.Error;
+ in string;
+ out uint32;
+ err os.Error;
}
-var atoui32tests = []atoui32Test {
+var atoui32tests = []atoui32Test{
atoui32Test{"", 0, os.EINVAL},
atoui32Test{"0", 0, nil},
atoui32Test{"1", 1, nil},
@@ -84,17 +84,17 @@ var atoui32tests = []atoui32Test {
atoui32Test{"0X12345", 0x12345, nil},
atoui32Test{"12345x", 0, os.EINVAL},
atoui32Test{"987654321", 987654321, nil},
- atoui32Test{"4294967295", 1<<32-1, nil},
- atoui32Test{"4294967296", 1<<32-1, os.ERANGE},
+ atoui32Test{"4294967295", 1<<32 - 1, nil},
+ atoui32Test{"4294967296", 1<<32 - 1, os.ERANGE},
}
type atoi32Test struct {
- in string;
- out int32;
- err os.Error;
+ in string;
+ out int32;
+ err os.Error;
}
-var atoi32tests = []atoi32Test {
+var atoi32tests = []atoi32Test{
atoi32Test{"", 0, os.EINVAL},
atoi32Test{"0", 0, nil},
atoi32Test{"-0", 0, nil},
@@ -110,12 +110,12 @@ var atoi32tests = []atoi32Test {
atoi32Test{"-12345x", 0, os.EINVAL},
atoi32Test{"987654321", 987654321, nil},
atoi32Test{"-987654321", -987654321, nil},
- atoi32Test{"2147483647", 1<<31-1, nil},
- atoi32Test{"-2147483647", -(1<<31-1), nil},
- atoi32Test{"2147483648", 1<<31-1, os.ERANGE},
- atoi32Test{"-2147483648", -1<<31, nil},
- atoi32Test{"2147483649", 1<<31-1, os.ERANGE},
- atoi32Test{"-2147483649", -1<<31, os.ERANGE},
+ atoi32Test{"2147483647", 1<<31 - 1, nil},
+ atoi32Test{"-2147483647", -(1<<31 - 1), nil},
+ atoi32Test{"2147483648", 1<<31 - 1, os.ERANGE},
+ atoi32Test{"-2147483648", -1 << 31, nil},
+ atoi32Test{"2147483649", 1<<31 - 1, os.ERANGE},
+ atoi32Test{"-2147483649", -1 << 31, os.ERANGE},
}
func init() {
@@ -124,25 +124,25 @@ func init() {
for i := range atoui64tests {
test := &atoui64tests[i];
if test.err != nil {
- test.err = &NumError{test.in, test.err}
+ test.err = &NumError{test.in, test.err};
}
}
for i := range atoi64tests {
test := &atoi64tests[i];
if test.err != nil {
- test.err = &NumError{test.in, test.err}
+ test.err = &NumError{test.in, test.err};
}
}
for i := range atoui32tests {
test := &atoui32tests[i];
if test.err != nil {
- test.err = &NumError{test.in, test.err}
+ test.err = &NumError{test.in, test.err};
}
}
for i := range atoi32tests {
test := &atoi32tests[i];
if test.err != nil {
- test.err = &NumError{test.in, test.err}
+ test.err = &NumError{test.in, test.err};
}
}
}
@@ -214,4 +214,3 @@ func TestAtoi(t *testing.T) {
}
}
}
-
diff --git a/src/pkg/strconv/decimal_test.go b/src/pkg/strconv/decimal_test.go
index 5254cf9a8..443e057e8 100644
--- a/src/pkg/strconv/decimal_test.go
+++ b/src/pkg/strconv/decimal_test.go
@@ -5,27 +5,28 @@
package strconv_test
import (
- . "strconv";
- "testing";
+ . "strconv";
+ "testing";
)
type shiftTest struct {
- i uint64;
- shift int;
- out string;
+ i uint64;
+ shift int;
+ out string;
}
-var shifttests = []shiftTest {
- shiftTest{ 0, -100, "0" },
- shiftTest{ 0, 100, "0" },
- shiftTest{ 1, 100, "1267650600228229401496703205376" },
- shiftTest{ 1, -100,
+var shifttests = []shiftTest{
+ shiftTest{0, -100, "0"},
+ shiftTest{0, 100, "0"},
+ shiftTest{1, 100, "1267650600228229401496703205376"},
+ shiftTest{1, -100,
"0.00000000000000000000000000000078886090522101180541"
- "17285652827862296732064351090230047702789306640625" },
- shiftTest{ 12345678, 8, "3160493568" },
- shiftTest{ 12345678, -8, "48225.3046875" },
- shiftTest{ 195312, 9, "99999744" },
- shiftTest{ 1953125, 9, "1000000000" },
+ "17285652827862296732064351090230047702789306640625",
+ },
+ shiftTest{12345678, 8, "3160493568"},
+ shiftTest{12345678, -8, "48225.3046875"},
+ shiftTest{195312, 9, "99999744"},
+ shiftTest{1953125, 9, "1000000000"},
}
func TestDecimalShift(t *testing.T) {
@@ -40,28 +41,28 @@ func TestDecimalShift(t *testing.T) {
}
type roundTest struct {
- i uint64;
- nd int;
- down, round, up string;
- int uint64;
+ i uint64;
+ nd int;
+ down, round, up string;
+ int uint64;
}
-var roundtests = []roundTest {
- roundTest{ 0, 4, "0", "0", "0", 0 },
- roundTest{ 12344999, 4, "12340000", "12340000", "12350000", 12340000 },
- roundTest{ 12345000, 4, "12340000", "12340000", "12350000", 12340000 },
- roundTest{ 12345001, 4, "12340000", "12350000", "12350000", 12350000 },
- roundTest{ 23454999, 4, "23450000", "23450000", "23460000", 23450000 },
- roundTest{ 23455000, 4, "23450000", "23460000", "23460000", 23460000 },
- roundTest{ 23455001, 4, "23450000", "23460000", "23460000", 23460000 },
+var roundtests = []roundTest{
+ roundTest{0, 4, "0", "0", "0", 0},
+ roundTest{12344999, 4, "12340000", "12340000", "12350000", 12340000},
+ roundTest{12345000, 4, "12340000", "12340000", "12350000", 12340000},
+ roundTest{12345001, 4, "12340000", "12350000", "12350000", 12350000},
+ roundTest{23454999, 4, "23450000", "23450000", "23460000", 23450000},
+ roundTest{23455000, 4, "23450000", "23460000", "23460000", 23460000},
+ roundTest{23455001, 4, "23450000", "23460000", "23460000", 23460000},
- roundTest{ 99994999, 4, "99990000", "99990000", "100000000", 99990000 },
- roundTest{ 99995000, 4, "99990000", "100000000", "100000000", 100000000 },
- roundTest{ 99999999, 4, "99990000", "100000000", "100000000", 100000000 },
+ roundTest{99994999, 4, "99990000", "99990000", "100000000", 99990000},
+ roundTest{99995000, 4, "99990000", "100000000", "100000000", 100000000},
+ roundTest{99999999, 4, "99990000", "100000000", "100000000", 100000000},
- roundTest{ 12994999, 4, "12990000", "12990000", "13000000", 12990000 },
- roundTest{ 12995000, 4, "12990000", "13000000", "13000000", 13000000 },
- roundTest{ 12999999, 4, "12990000", "13000000", "13000000", 13000000 },
+ roundTest{12994999, 4, "12990000", "12990000", "13000000", 12990000},
+ roundTest{12995000, 4, "12990000", "13000000", "13000000", 13000000},
+ roundTest{12999999, 4, "12990000", "13000000", "13000000", 13000000},
}
func TestDecimalRound(t *testing.T) {
@@ -86,22 +87,22 @@ func TestDecimalRound(t *testing.T) {
}
type roundIntTest struct {
- i uint64;
- shift int;
- int uint64;
+ i uint64;
+ shift int;
+ int uint64;
}
-var roundinttests = []roundIntTest {
- roundIntTest{ 0, 100, 0 },
- roundIntTest{ 512, -8, 2 },
- roundIntTest{ 513, -8, 2 },
- roundIntTest{ 640, -8, 2 },
- roundIntTest{ 641, -8, 3 },
- roundIntTest{ 384, -8, 2 },
- roundIntTest{ 385, -8, 2 },
- roundIntTest{ 383, -8, 1 },
- roundIntTest{ 1, 100, 1<<64-1 },
- roundIntTest{ 1000, 0, 1000 },
+var roundinttests = []roundIntTest{
+ roundIntTest{0, 100, 0},
+ roundIntTest{512, -8, 2},
+ roundIntTest{513, -8, 2},
+ roundIntTest{640, -8, 2},
+ roundIntTest{641, -8, 3},
+ roundIntTest{384, -8, 2},
+ roundIntTest{385, -8, 2},
+ roundIntTest{383, -8, 1},
+ roundIntTest{1, 100, 1<<64 - 1},
+ roundIntTest{1000, 0, 1000},
}
func TestDecimalRoundedInteger(t *testing.T) {
diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go
index 89092a634..6f25acf78 100644
--- a/src/pkg/strconv/fp_test.go
+++ b/src/pkg/strconv/fp_test.go
@@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.
package strconv_test
+
import (
"bufio";
"fmt";
@@ -21,7 +22,7 @@ func pow2(i int) float64 {
case i == 1:
return 2;
}
- return pow2(i/2) * pow2(i-i/2);
+ return pow2(i/2) * pow2(i - i/2);
}
// Wrapper around strconv.Atof64. Handles dddddp+ddd (binary exponent)
@@ -110,10 +111,10 @@ func TestFp(t *testing.T) {
if err2 != nil {
panicln("testfp: read testfp.txt:", err2.String());
}
- line = line[0:len(line)-1];
+ line = line[0 : len(line)-1];
lineno++;
if len(line) == 0 || line[0] == '#' {
- continue
+ continue;
}
a := strings.Split(line, " ", 0);
if len(a) != 4 {
diff --git a/src/pkg/strconv/ftoa_test.go b/src/pkg/strconv/ftoa_test.go
index 44402439c..45cdfbfc9 100644
--- a/src/pkg/strconv/ftoa_test.go
+++ b/src/pkg/strconv/ftoa_test.go
@@ -5,98 +5,100 @@
package strconv_test
import (
- "math";
- . "strconv";
- "testing";
+ "math";
+ . "strconv";
+ "testing";
)
type ftoaTest struct {
- f float64;
- fmt byte;
- prec int;
- s string;
+ f float64;
+ fmt byte;
+ prec int;
+ s string;
}
-func fdiv(a, b float64) float64 { return a / b } // keep compiler in the dark
+func fdiv(a, b float64) float64 {
+ return a/b;
+} // keep compiler in the dark
const (
- below1e23 = 99999999999999974834176;
- above1e23 = 100000000000000008388608;
+ below1e23 = 99999999999999974834176;
+ above1e23 = 100000000000000008388608;
)
-var ftoatests = []ftoaTest {
- ftoaTest{ 1, 'e', 5, "1.00000e+00" },
- ftoaTest{ 1, 'f', 5, "1.00000" },
- ftoaTest{ 1, 'g', 5, "1" },
- ftoaTest{ 1, 'g', -1, "1" },
- ftoaTest{ 20, 'g', -1, "20" },
- ftoaTest{ 1234567.8, 'g', -1, "1.2345678e+06" },
- ftoaTest{ 200000, 'g', -1, "200000" },
- ftoaTest{ 2000000, 'g', -1, "2e+06" },
-
- ftoaTest{ 0, 'e', 5, "0.00000e+00" },
- ftoaTest{ 0, 'f', 5, "0.00000" },
- ftoaTest{ 0, 'g', 5, "0" },
- ftoaTest{ 0, 'g', -1, "0" },
-
- ftoaTest{ -1, 'e', 5, "-1.00000e+00" },
- ftoaTest{ -1, 'f', 5, "-1.00000" },
- ftoaTest{ -1, 'g', 5, "-1" },
- ftoaTest{ -1, 'g', -1, "-1" },
-
- ftoaTest{ 12, 'e', 5, "1.20000e+01" },
- ftoaTest{ 12, 'f', 5, "12.00000" },
- ftoaTest{ 12, 'g', 5, "12" },
- ftoaTest{ 12, 'g', -1, "12" },
-
- ftoaTest{ 123456700, 'e', 5, "1.23457e+08" },
- ftoaTest{ 123456700, 'f', 5, "123456700.00000" },
- ftoaTest{ 123456700, 'g', 5, "1.2346e+08" },
- ftoaTest{ 123456700, 'g', -1, "1.234567e+08" },
-
- ftoaTest{ 1.2345e6, 'e', 5, "1.23450e+06" },
- ftoaTest{ 1.2345e6, 'f', 5, "1234500.00000" },
- ftoaTest{ 1.2345e6, 'g', 5, "1.2345e+06" },
-
- ftoaTest{ 1e23, 'e', 17, "9.99999999999999916e+22" },
- ftoaTest{ 1e23, 'f', 17, "99999999999999991611392.00000000000000000" },
- ftoaTest{ 1e23, 'g', 17, "9.9999999999999992e+22" },
-
- ftoaTest{ 1e23, 'e', -1, "1e+23" },
- ftoaTest{ 1e23, 'f', -1, "100000000000000000000000" },
- ftoaTest{ 1e23, 'g', -1, "1e+23" },
-
- ftoaTest{ below1e23, 'e', 17, "9.99999999999999748e+22" },
- ftoaTest{ below1e23, 'f', 17, "99999999999999974834176.00000000000000000" },
- ftoaTest{ below1e23, 'g', 17, "9.9999999999999975e+22" },
-
- ftoaTest{ below1e23, 'e', -1, "9.999999999999997e+22" },
- ftoaTest{ below1e23, 'f', -1, "99999999999999970000000" },
- ftoaTest{ below1e23, 'g', -1, "9.999999999999997e+22" },
-
- ftoaTest{ above1e23, 'e', 17, "1.00000000000000008e+23" },
- ftoaTest{ above1e23, 'f', 17, "100000000000000008388608.00000000000000000" },
- ftoaTest{ above1e23, 'g', 17, "1.0000000000000001e+23" },
-
- ftoaTest{ above1e23, 'e', -1, "1.0000000000000001e+23" },
- ftoaTest{ above1e23, 'f', -1, "100000000000000010000000" },
- ftoaTest{ above1e23, 'g', -1, "1.0000000000000001e+23" },
-
- ftoaTest{ fdiv(5e-304, 1e20), 'g', -1, "5e-324" },
- ftoaTest{ fdiv(-5e-304, 1e20), 'g', -1, "-5e-324" },
-
- ftoaTest{ 32, 'g', -1, "32" },
- ftoaTest{ 32, 'g', 0, "3e+01" },
-
- ftoaTest{ 100, 'x', -1, "%x" },
-
- ftoaTest{ math.NaN(), 'g', -1, "NaN" },
- ftoaTest{ -math.NaN(), 'g', -1, "NaN" },
- ftoaTest{ math.Inf(0), 'g', -1, "+Inf" },
- ftoaTest{ math.Inf(-1), 'g', -1, "-Inf" },
- ftoaTest{ -math.Inf(0), 'g', -1, "-Inf" },
-
- ftoaTest{ -1, 'b', -1, "-4503599627370496p-52" },
+var ftoatests = []ftoaTest{
+ ftoaTest{1, 'e', 5, "1.00000e+00"},
+ ftoaTest{1, 'f', 5, "1.00000"},
+ ftoaTest{1, 'g', 5, "1"},
+ ftoaTest{1, 'g', -1, "1"},
+ ftoaTest{20, 'g', -1, "20"},
+ ftoaTest{1234567.8, 'g', -1, "1.2345678e+06"},
+ ftoaTest{200000, 'g', -1, "200000"},
+ ftoaTest{2000000, 'g', -1, "2e+06"},
+
+ ftoaTest{0, 'e', 5, "0.00000e+00"},
+ ftoaTest{0, 'f', 5, "0.00000"},
+ ftoaTest{0, 'g', 5, "0"},
+ ftoaTest{0, 'g', -1, "0"},
+
+ ftoaTest{-1, 'e', 5, "-1.00000e+00"},
+ ftoaTest{-1, 'f', 5, "-1.00000"},
+ ftoaTest{-1, 'g', 5, "-1"},
+ ftoaTest{-1, 'g', -1, "-1"},
+
+ ftoaTest{12, 'e', 5, "1.20000e+01"},
+ ftoaTest{12, 'f', 5, "12.00000"},
+ ftoaTest{12, 'g', 5, "12"},
+ ftoaTest{12, 'g', -1, "12"},
+
+ ftoaTest{123456700, 'e', 5, "1.23457e+08"},
+ ftoaTest{123456700, 'f', 5, "123456700.00000"},
+ ftoaTest{123456700, 'g', 5, "1.2346e+08"},
+ ftoaTest{123456700, 'g', -1, "1.234567e+08"},
+
+ ftoaTest{1.2345e6, 'e', 5, "1.23450e+06"},
+ ftoaTest{1.2345e6, 'f', 5, "1234500.00000"},
+ ftoaTest{1.2345e6, 'g', 5, "1.2345e+06"},
+
+ ftoaTest{1e23, 'e', 17, "9.99999999999999916e+22"},
+ ftoaTest{1e23, 'f', 17, "99999999999999991611392.00000000000000000"},
+ ftoaTest{1e23, 'g', 17, "9.9999999999999992e+22"},
+
+ ftoaTest{1e23, 'e', -1, "1e+23"},
+ ftoaTest{1e23, 'f', -1, "100000000000000000000000"},
+ ftoaTest{1e23, 'g', -1, "1e+23"},
+
+ ftoaTest{below1e23, 'e', 17, "9.99999999999999748e+22"},
+ ftoaTest{below1e23, 'f', 17, "99999999999999974834176.00000000000000000"},
+ ftoaTest{below1e23, 'g', 17, "9.9999999999999975e+22"},
+
+ ftoaTest{below1e23, 'e', -1, "9.999999999999997e+22"},
+ ftoaTest{below1e23, 'f', -1, "99999999999999970000000"},
+ ftoaTest{below1e23, 'g', -1, "9.999999999999997e+22"},
+
+ ftoaTest{above1e23, 'e', 17, "1.00000000000000008e+23"},
+ ftoaTest{above1e23, 'f', 17, "100000000000000008388608.00000000000000000"},
+ ftoaTest{above1e23, 'g', 17, "1.0000000000000001e+23"},
+
+ ftoaTest{above1e23, 'e', -1, "1.0000000000000001e+23"},
+ ftoaTest{above1e23, 'f', -1, "100000000000000010000000"},
+ ftoaTest{above1e23, 'g', -1, "1.0000000000000001e+23"},
+
+ ftoaTest{fdiv(5e-304, 1e20), 'g', -1, "5e-324"},
+ ftoaTest{fdiv(-5e-304, 1e20), 'g', -1, "-5e-324"},
+
+ ftoaTest{32, 'g', -1, "32"},
+ ftoaTest{32, 'g', 0, "3e+01"},
+
+ ftoaTest{100, 'x', -1, "%x"},
+
+ ftoaTest{math.NaN(), 'g', -1, "NaN"},
+ ftoaTest{-math.NaN(), 'g', -1, "NaN"},
+ ftoaTest{math.Inf(0), 'g', -1, "+Inf"},
+ ftoaTest{math.Inf(-1), 'g', -1, "-Inf"},
+ ftoaTest{-math.Inf(0), 'g', -1, "-Inf"},
+
+ ftoaTest{-1, 'b', -1, "-4503599627370496p-52"},
}
func TestFtoa(t *testing.T) {
diff --git a/src/pkg/strconv/internal_test.go b/src/pkg/strconv/internal_test.go
index 8ec75db35..428c94e00 100644
--- a/src/pkg/strconv/internal_test.go
+++ b/src/pkg/strconv/internal_test.go
@@ -15,4 +15,3 @@ func SetOptimize(b bool) bool {
optimize = b;
return old;
}
-
diff --git a/src/pkg/strconv/itoa.go b/src/pkg/strconv/itoa.go
index c6985f438..15fa30627 100644
--- a/src/pkg/strconv/itoa.go
+++ b/src/pkg/strconv/itoa.go
@@ -7,7 +7,7 @@ package strconv
// Uitob64 returns the string representation of i in the given base.
func Uitob64(u uint64, base uint) string {
if u == 0 {
- return "0"
+ return "0";
}
// Assemble decimal in reverse order.
@@ -20,13 +20,13 @@ func Uitob64(u uint64, base uint) string {
u /= b;
}
- return string(buf[j:len(buf)])
+ return string(buf[j:len(buf)]);
}
// Itob64 returns the string representation of i in the given base.
func Itob64(i int64, base uint) string {
if i == 0 {
- return "0"
+ return "0";
}
if i < 0 {
diff --git a/src/pkg/strconv/itoa_test.go b/src/pkg/strconv/itoa_test.go
index 56f5fb97c..38243f0e8 100644
--- a/src/pkg/strconv/itoa_test.go
+++ b/src/pkg/strconv/itoa_test.go
@@ -5,56 +5,56 @@
package strconv_test
import (
- . "strconv";
- "testing";
+ . "strconv";
+ "testing";
)
type itob64Test struct {
- in int64;
- base uint;
- out string;
+ in int64;
+ base uint;
+ out string;
}
-var itob64tests = []itob64Test {
- itob64Test{ 0, 10, "0" },
- itob64Test{ 1, 10, "1" },
- itob64Test{ -1, 10, "-1" },
- itob64Test{ 12345678, 10, "12345678" },
- itob64Test{ -987654321, 10, "-987654321" },
- itob64Test{ 1<<31-1, 10, "2147483647" },
- itob64Test{ -1<<31+1, 10, "-2147483647" },
- itob64Test{ 1<<31, 10, "2147483648" },
- itob64Test{ -1<<31, 10, "-2147483648" },
- itob64Test{ 1<<31+1, 10, "2147483649" },
- itob64Test{ -1<<31-1, 10, "-2147483649" },
- itob64Test{ 1<<32-1, 10, "4294967295" },
- itob64Test{ -1<<32+1, 10, "-4294967295" },
- itob64Test{ 1<<32, 10, "4294967296" },
- itob64Test{ -1<<32, 10, "-4294967296" },
- itob64Test{ 1<<32+1, 10, "4294967297" },
- itob64Test{ -1<<32-1, 10, "-4294967297" },
- itob64Test{ 1<<50, 10, "1125899906842624" },
- itob64Test{ 1<<63-1, 10, "9223372036854775807" },
- itob64Test{ -1<<63+1, 10, "-9223372036854775807" },
- itob64Test{ -1<<63, 10, "-9223372036854775808" },
-
- itob64Test{ 0, 2, "0" },
- itob64Test{ 10, 2, "1010" },
- itob64Test{ -1, 2, "-1" },
- itob64Test{ 1<<15, 2, "1000000000000000" },
-
- itob64Test{ -8, 8, "-10" },
- itob64Test{ 057635436545, 8, "57635436545" },
- itob64Test{ 1<<24, 8, "100000000" },
-
- itob64Test{ 16, 16, "10" },
- itob64Test{ -0x123456789abcdef, 16, "-123456789abcdef" },
- itob64Test{ 1<<63-1, 16, "7fffffffffffffff" },
-
- itob64Test{ 16, 17, "g" },
- itob64Test{ 25, 25, "10" },
- itob64Test{ (((((17*35+24)*35+21)*35+34)*35+12)*35+24)*35+32, 35, "holycow" },
- itob64Test{ (((((17*36+24)*36+21)*36+34)*36+12)*36+24)*36+32, 36, "holycow" },
+var itob64tests = []itob64Test{
+ itob64Test{0, 10, "0"},
+ itob64Test{1, 10, "1"},
+ itob64Test{-1, 10, "-1"},
+ itob64Test{12345678, 10, "12345678"},
+ itob64Test{-987654321, 10, "-987654321"},
+ itob64Test{1<<31 - 1, 10, "2147483647"},
+ itob64Test{-1 << 31 + 1, 10, "-2147483647"},
+ itob64Test{1<<31, 10, "2147483648"},
+ itob64Test{-1 << 31, 10, "-2147483648"},
+ itob64Test{1<<31 + 1, 10, "2147483649"},
+ itob64Test{-1 << 31 - 1, 10, "-2147483649"},
+ itob64Test{1<<32 - 1, 10, "4294967295"},
+ itob64Test{-1 << 32 + 1, 10, "-4294967295"},
+ itob64Test{1<<32, 10, "4294967296"},
+ itob64Test{-1 << 32, 10, "-4294967296"},
+ itob64Test{1<<32 + 1, 10, "4294967297"},
+ itob64Test{-1 << 32 - 1, 10, "-4294967297"},
+ itob64Test{1<<50, 10, "1125899906842624"},
+ itob64Test{1<<63 - 1, 10, "9223372036854775807"},
+ itob64Test{-1 << 63 + 1, 10, "-9223372036854775807"},
+ itob64Test{-1 << 63, 10, "-9223372036854775808"},
+
+ itob64Test{0, 2, "0"},
+ itob64Test{10, 2, "1010"},
+ itob64Test{-1, 2, "-1"},
+ itob64Test{1<<15, 2, "1000000000000000"},
+
+ itob64Test{-8, 8, "-10"},
+ itob64Test{057635436545, 8, "57635436545"},
+ itob64Test{1<<24, 8, "100000000"},
+
+ itob64Test{16, 16, "10"},
+ itob64Test{-0x123456789abcdef, 16, "-123456789abcdef"},
+ itob64Test{1<<63 - 1, 16, "7fffffffffffffff"},
+
+ itob64Test{16, 17, "g"},
+ itob64Test{25, 25, "10"},
+ itob64Test{(((((17*35 + 24)*35 + 21)*35 + 34)*35 + 12)*35 + 24)*35 + 32, 35, "holycow"},
+ itob64Test{(((((17*36 + 24)*36 + 21)*36 + 34)*36 + 12)*36 + 24)*36 + 32, 36, "holycow"},
}
func TestItoa(t *testing.T) {
@@ -80,7 +80,7 @@ func TestItoa(t *testing.T) {
test.in, test.base, s, test.out);
}
- if test.in >= 0 {
+ if test.in >= 0 {
s := Uitob(uint(test.in), test.base);
if s != test.out {
t.Errorf("Uitob(%v, %v) = %v want %v\n",
@@ -124,17 +124,17 @@ func TestItoa(t *testing.T) {
}
type uitob64Test struct {
- in uint64;
- base uint;
- out string;
+ in uint64;
+ base uint;
+ out string;
}
-var uitob64tests = []uitob64Test {
- uitob64Test{ 1<<63-1, 10, "9223372036854775807" },
- uitob64Test{ 1<<63, 10, "9223372036854775808" },
- uitob64Test{ 1<<63+1, 10, "9223372036854775809" },
- uitob64Test{ 1<<64-2, 10, "18446744073709551614" },
- uitob64Test{ 1<<64-1, 10, "18446744073709551615" },
+var uitob64tests = []uitob64Test{
+ uitob64Test{1<<63 - 1, 10, "9223372036854775807"},
+ uitob64Test{1<<63, 10, "9223372036854775808"},
+ uitob64Test{1<<63 + 1, 10, "9223372036854775809"},
+ uitob64Test{1<<64 - 2, 10, "18446744073709551614"},
+ uitob64Test{1<<64 - 1, 10, "18446744073709551615"},
}
func TestUitoa(t *testing.T) {
diff --git a/src/pkg/strconv/quote.go b/src/pkg/strconv/quote.go
index e343f670c..9db6b2dc3 100644
--- a/src/pkg/strconv/quote.go
+++ b/src/pkg/strconv/quote.go
@@ -43,23 +43,23 @@ func Quote(s string) string {
t += `\v`;
case c < utf8.RuneSelf:
- t += `\x` + string(lowerhex[c>>4]) + string(lowerhex[c&0xF]);
+ t += `\x`+string(lowerhex[c>>4])+string(lowerhex[c&0xF]);
case utf8.FullRuneInString(s):
r, size := utf8.DecodeRuneInString(s);
if r == utf8.RuneError && size == 1 {
goto EscX;
}
- s = s[size-1:len(s)]; // next iteration will slice off 1 more
+ s = s[size-1 : len(s)]; // next iteration will slice off 1 more
if r < 0x10000 {
t += `\u`;
- for j:=uint(0); j<4; j++ {
- t += string(lowerhex[(r>>(12-4*j))&0xF]);
+ for j := uint(0); j < 4; j++ {
+ t += string(lowerhex[(r>>(12 - 4*j))&0xF]);
}
} else {
t += `\U`;
- for j:=uint(0); j<8; j++ {
- t += string(lowerhex[(r>>(28-4*j))&0xF]);
+ for j := uint(0); j < 8; j++ {
+ t += string(lowerhex[(r>>(28 - 4*j))&0xF]);
}
}
@@ -89,18 +89,18 @@ func unhex(b byte) (v int, ok bool) {
c := int(b);
switch {
case '0' <= c && c <= '9':
- return c - '0', true;
+ return c-'0', true;
case 'a' <= c && c <= 'f':
- return c - 'a' + 10, true;
+ return c-'a'+10, true;
case 'A' <= c && c <= 'F':
- return c - 'A' + 10, true;
+ return c-'A'+10, true;
}
return;
}
// UnquoteChar decodes the first character or byte in the escaped string
// or character literal represented by the string s.
-// It returns four values:
+// It returns four values:
// 1) value, the decoded Unicode code point or byte value;
// 2) multibyte, a boolean indicating whether the decoded character
// requires a multibyte UTF-8 representation;
@@ -183,17 +183,17 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
value = v;
multibyte = true;
case '0', '1', '2', '3', '4', '5', '6', '7':
- v := int(c) - '0';
+ v := int(c)-'0';
if len(s) < 2 {
err = os.EINVAL;
return;
}
for j := 0; j < 2; j++ { // one digit already; two more
- x := int(s[j]) - '0';
+ x := int(s[j])-'0';
if x < 0 || x > 7 {
return;
}
- v = (v<<3) | x;
+ v = (v<<3)|x;
}
s = s[2:len(s)];
if v > 255 {
@@ -223,7 +223,7 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
// character literal; Unquote returns the corresponding
// one-character string.)
func Unquote(s string) (t string, err os.Error) {
- err = os.EINVAL; // assume error for easy return
+ err = os.EINVAL; // assume error for easy return
n := len(s);
if n < 2 {
return;
@@ -232,7 +232,7 @@ func Unquote(s string) (t string, err os.Error) {
if quote != s[n-1] {
return;
}
- s = s[1:n-1];
+ s = s[1 : n-1];
if quote == '`' {
return s, nil;
@@ -260,5 +260,5 @@ func Unquote(s string) (t string, err os.Error) {
return;
}
}
- return tt, nil
+ return tt, nil;
}
diff --git a/src/pkg/strconv/quote_test.go b/src/pkg/strconv/quote_test.go
index a3d7ab939..c15e62622 100644
--- a/src/pkg/strconv/quote_test.go
+++ b/src/pkg/strconv/quote_test.go
@@ -5,23 +5,23 @@
package strconv_test
import (
- "os";
- . "strconv";
- "testing";
+ "os";
+ . "strconv";
+ "testing";
)
type quoteTest struct {
- in string;
- out string;
+ in string;
+ out string;
}
-var quotetests = []quoteTest {
- quoteTest{ "\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"` },
- quoteTest{ "\\", `"\\"` },
- quoteTest{ "abc\xffdef", `"abc\xffdef"` },
- quoteTest{ "\u263a", `"\u263a"` },
- quoteTest{ "\U0010ffff", `"\U0010ffff"` },
- quoteTest{ "\x04", `"\x04"` },
+var quotetests = []quoteTest{
+ quoteTest{"\a\b\f\r\n\t\v", `"\a\b\f\r\n\t\v"`},
+ quoteTest{"\\", `"\\"`},
+ quoteTest{"abc\xffdef", `"abc\xffdef"`},
+ quoteTest{"\u263a", `"\u263a"`},
+ quoteTest{"\U0010ffff", `"\U0010ffff"`},
+ quoteTest{"\x04", `"\x04"`},
}
func TestQuote(t *testing.T) {
@@ -34,49 +34,49 @@ func TestQuote(t *testing.T) {
}
type canBackquoteTest struct {
- in string;
- out bool;
+ in string;
+ out bool;
}
-var canbackquotetests = []canBackquoteTest {
- canBackquoteTest{ "`", false },
- canBackquoteTest{ string(0), false },
- canBackquoteTest{ string(1), false },
- canBackquoteTest{ string(2), false },
- canBackquoteTest{ string(3), false },
- canBackquoteTest{ string(4), false },
- canBackquoteTest{ string(5), false },
- canBackquoteTest{ string(6), false },
- canBackquoteTest{ string(7), false },
- canBackquoteTest{ string(8), false },
- canBackquoteTest{ string(9), true }, // \t
- canBackquoteTest{ string(10), false },
- canBackquoteTest{ string(11), false },
- canBackquoteTest{ string(12), false },
- canBackquoteTest{ string(13), false },
- canBackquoteTest{ string(14), false },
- canBackquoteTest{ string(15), false },
- canBackquoteTest{ string(16), false },
- canBackquoteTest{ string(17), false },
- canBackquoteTest{ string(18), false },
- canBackquoteTest{ string(19), false },
- canBackquoteTest{ string(20), false },
- canBackquoteTest{ string(21), false },
- canBackquoteTest{ string(22), false },
- canBackquoteTest{ string(23), false },
- canBackquoteTest{ string(24), false },
- canBackquoteTest{ string(25), false },
- canBackquoteTest{ string(26), false },
- canBackquoteTest{ string(27), false },
- canBackquoteTest{ string(28), false },
- canBackquoteTest{ string(29), false },
- canBackquoteTest{ string(30), false },
- canBackquoteTest{ string(31), false },
- canBackquoteTest{ `' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true },
- canBackquoteTest{ `0123456789`, true },
- canBackquoteTest{ `ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true },
- canBackquoteTest{ `abcdefghijklmnopqrstuvwxyz`, true },
- canBackquoteTest{ `☺`, true },
+var canbackquotetests = []canBackquoteTest{
+ canBackquoteTest{"`", false},
+ canBackquoteTest{string(0), false},
+ canBackquoteTest{string(1), false},
+ canBackquoteTest{string(2), false},
+ canBackquoteTest{string(3), false},
+ canBackquoteTest{string(4), false},
+ canBackquoteTest{string(5), false},
+ canBackquoteTest{string(6), false},
+ canBackquoteTest{string(7), false},
+ canBackquoteTest{string(8), false},
+ canBackquoteTest{string(9), true}, // \t
+ canBackquoteTest{string(10), false},
+ canBackquoteTest{string(11), false},
+ canBackquoteTest{string(12), false},
+ canBackquoteTest{string(13), false},
+ canBackquoteTest{string(14), false},
+ canBackquoteTest{string(15), false},
+ canBackquoteTest{string(16), false},
+ canBackquoteTest{string(17), false},
+ canBackquoteTest{string(18), false},
+ canBackquoteTest{string(19), false},
+ canBackquoteTest{string(20), false},
+ canBackquoteTest{string(21), false},
+ canBackquoteTest{string(22), false},
+ canBackquoteTest{string(23), false},
+ canBackquoteTest{string(24), false},
+ canBackquoteTest{string(25), false},
+ canBackquoteTest{string(26), false},
+ canBackquoteTest{string(27), false},
+ canBackquoteTest{string(28), false},
+ canBackquoteTest{string(29), false},
+ canBackquoteTest{string(30), false},
+ canBackquoteTest{string(31), false},
+ canBackquoteTest{`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true},
+ canBackquoteTest{`0123456789`, true},
+ canBackquoteTest{`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true},
+ canBackquoteTest{`abcdefghijklmnopqrstuvwxyz`, true},
+ canBackquoteTest{`☺`, true},
}
func TestCanBackquote(t *testing.T) {
@@ -88,45 +88,45 @@ func TestCanBackquote(t *testing.T) {
}
}
-var unquotetests = []quoteTest {
- quoteTest{ `""`, "" },
- quoteTest{ `"a"`, "a" },
- quoteTest{ `"abc"`, "abc" },
- quoteTest{ `"☺"`, "☺" },
- quoteTest{ `"hello world"`, "hello world" },
- quoteTest{ `"\xFF"`, "\xFF" },
- quoteTest{ `"\377"`, "\377" },
- quoteTest{ `"\u1234"`, "\u1234" },
- quoteTest{ `"\U00010111"`, "\U00010111" },
- quoteTest{ `"\U0001011111"`, "\U0001011111" },
- quoteTest{ `"\a\b\f\n\r\t\v\\\""`, "\a\b\f\n\r\t\v\\\"" },
- quoteTest{ `"'"`, "'" },
+var unquotetests = []quoteTest{
+ quoteTest{`""`, ""},
+ quoteTest{`"a"`, "a"},
+ quoteTest{`"abc"`, "abc"},
+ quoteTest{`"☺"`, "☺"},
+ quoteTest{`"hello world"`, "hello world"},
+ quoteTest{`"\xFF"`, "\xFF"},
+ quoteTest{`"\377"`, "\377"},
+ quoteTest{`"\u1234"`, "\u1234"},
+ quoteTest{`"\U00010111"`, "\U00010111"},
+ quoteTest{`"\U0001011111"`, "\U0001011111"},
+ quoteTest{`"\a\b\f\n\r\t\v\\\""`, "\a\b\f\n\r\t\v\\\""},
+ quoteTest{`"'"`, "'"},
- quoteTest{ `'a'`, "a" },
- quoteTest{ `'☹'`, "☹" },
- quoteTest{ `'\a'`, "\a" },
- quoteTest{ `'\x10'`, "\x10" },
- quoteTest{ `'\377'`, "\377" },
- quoteTest{ `'\u1234'`, "\u1234" },
- quoteTest{ `'\U00010111'`, "\U00010111" },
- quoteTest{ `'\t'`, "\t" },
- quoteTest{ `' '`, " " },
- quoteTest{ `'\''`, "'" },
- quoteTest{ `'"'`, "\"" },
+ quoteTest{`'a'`, "a"},
+ quoteTest{`'☹'`, "☹"},
+ quoteTest{`'\a'`, "\a"},
+ quoteTest{`'\x10'`, "\x10"},
+ quoteTest{`'\377'`, "\377"},
+ quoteTest{`'\u1234'`, "\u1234"},
+ quoteTest{`'\U00010111'`, "\U00010111"},
+ quoteTest{`'\t'`, "\t"},
+ quoteTest{`' '`, " "},
+ quoteTest{`'\''`, "'"},
+ quoteTest{`'"'`, "\""},
- quoteTest{ "``", `` },
- quoteTest{ "`a`", `a` },
- quoteTest{ "`abc`", `abc` },
- quoteTest{ "`☺`", `☺` },
- quoteTest{ "`hello world`", `hello world` },
- quoteTest{ "`\\xFF`", `\xFF` },
- quoteTest{ "`\\377`", `\377` },
- quoteTest{ "`\\`", `\` },
- quoteTest{ "` `", ` ` },
- quoteTest{ "` `", ` ` },
+ quoteTest{"``", ``},
+ quoteTest{"`a`", `a`},
+ quoteTest{"`abc`", `abc`},
+ quoteTest{"`☺`", `☺`},
+ quoteTest{"`hello world`", `hello world`},
+ quoteTest{"`\\xFF`", `\xFF`},
+ quoteTest{"`\\377`", `\377`},
+ quoteTest{"`\\`", `\`},
+ quoteTest{"` `", ` `},
+ quoteTest{"` `", ` `},
}
-var misquoted = []string {
+var misquoted = []string{
``,
`"`,
`"a`,