summaryrefslogtreecommitdiff
path: root/src/pkg/strconv
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-11-09 12:07:39 -0800
committerRobert Griesemer <gri@golang.org>2009-11-09 12:07:39 -0800
commite940edc7a026293153ba09ece40e8092a2fc2463 (patch)
treec94a425c84b7a48f91a5d76a222effad70c9a88c /src/pkg/strconv
parente067f862f1774ab89a2096a88571a94e3b9cd353 (diff)
downloadgolang-e940edc7a026293153ba09ece40e8092a2fc2463.tar.gz
remove semis after statements in one-statement statement lists
R=rsc, r http://go/go-review/1025029
Diffstat (limited to 'src/pkg/strconv')
-rw-r--r--src/pkg/strconv/atof.go62
-rw-r--r--src/pkg/strconv/atof_test.go8
-rw-r--r--src/pkg/strconv/atoi.go34
-rw-r--r--src/pkg/strconv/atoi_test.go28
-rw-r--r--src/pkg/strconv/decimal.go40
-rw-r--r--src/pkg/strconv/decimal_test.go10
-rw-r--r--src/pkg/strconv/fp_test.go22
-rw-r--r--src/pkg/strconv/ftoa.go68
-rw-r--r--src/pkg/strconv/ftoa_test.go6
-rw-r--r--src/pkg/strconv/itoa.go6
-rw-r--r--src/pkg/strconv/itoa_test.go24
-rw-r--r--src/pkg/strconv/quote.go76
-rw-r--r--src/pkg/strconv/quote_test.go10
13 files changed, 197 insertions, 197 deletions
diff --git a/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go
index 3202978d8..4629a7e17 100644
--- a/src/pkg/strconv/atof.go
+++ b/src/pkg/strconv/atof.go
@@ -25,11 +25,11 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
// optional sign
if i >= len(s) {
- return;
+ return
}
switch {
case s[i] == '+':
- i++;
+ i++
case s[i] == '-':
neg = true;
i++;
@@ -43,7 +43,7 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
switch {
case s[i] == '.':
if sawdot {
- return;
+ return
}
sawdot = true;
b.dp = b.nd;
@@ -62,10 +62,10 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
break;
}
if !sawdigits {
- return;
+ return
}
if !sawdot {
- b.dp = b.nd;
+ b.dp = b.nd
}
// optional exponent moves decimal point.
@@ -76,29 +76,29 @@ func stringToDecimal(s string) (neg bool, d *decimal, trunc bool, ok bool) {
if i < len(s) && s[i] == 'e' {
i++;
if i >= len(s) {
- return;
+ return
}
esign := 1;
if s[i] == '+' {
- i++;
+ i++
} else if s[i] == '-' {
i++;
esign = -1;
}
if i >= len(s) || s[i] < '0' || s[i] > '9' {
- return;
+ return
}
e := 0;
for ; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
if e < 10000 {
- e = e*10 + int(s[i]) - '0';
+ e = e*10 + int(s[i]) - '0'
}
}
b.dp += e*esign;
}
if i != len(s) {
- return;
+ return
}
d = b;
@@ -124,7 +124,7 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
// These bounds are for 64-bit floats.
// Will have to change if we want to support 80-bit floats in the future.
if d.dp > 310 {
- goto overflow;
+ goto overflow
}
if d.dp < -330 {
// zero
@@ -138,9 +138,9 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
for d.dp > 0 {
var n int;
if d.dp >= len(powtab) {
- n = 27;
+ n = 27
} else {
- n = powtab[d.dp];
+ n = powtab[d.dp]
}
d.Shift(-n);
exp += n;
@@ -148,9 +148,9 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
for d.dp < 0 || d.dp == 0 && d.d[0] < '5' {
var n int;
if -d.dp >= len(powtab) {
- n = 27;
+ n = 27
} else {
- n = powtab[-d.dp];
+ n = powtab[-d.dp]
}
d.Shift(n);
exp -= n;
@@ -169,7 +169,7 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
}
if exp - flt.bias >= 1 << flt.expbits - 1 {
- goto overflow;
+ goto overflow
}
// Extract 1+flt.mantbits bits.
@@ -180,13 +180,13 @@ func decimalToFloatBits(neg bool, d *decimal, trunc bool, flt *floatInfo) (b uin
mant >>= 1;
exp++;
if exp - flt.bias >= 1 << flt.expbits - 1 {
- goto overflow;
+ goto overflow
}
}
// Denormalized?
if mant&(1 << flt.mantbits) == 0 {
- exp = flt.bias;
+ exp = flt.bias
}
goto out;
@@ -201,7 +201,7 @@ out:
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;
}
@@ -211,10 +211,10 @@ out:
func decimalAtof64Int(neg bool, d *decimal) float64 {
f := float64(0);
for i := 0; i < d.nd; i++ {
- f = f*10 + float64(d.d[i] - '0');
+ f = f*10 + float64(d.d[i] - '0')
}
if neg {
- f *= -1; // BUG work around 6g f = -f.
+ f *= -1 // BUG work around 6g f = -f.
}
return f;
}
@@ -222,10 +222,10 @@ func decimalAtof64Int(neg bool, d *decimal) float64 {
func decimalAtof32Int(neg bool, d *decimal) float32 {
f := float32(0);
for i := 0; i < d.nd; i++ {
- f = f*10 + float32(d.d[i] - '0');
+ f = f*10 + float32(d.d[i] - '0')
}
if neg {
- f *= -1; // BUG work around 6g f = -f.
+ f *= -1 // BUG work around 6g f = -f.
}
return f;
}
@@ -249,7 +249,7 @@ func decimalAtof64(neg bool, d *decimal, trunc bool) (f float64, ok bool) {
// Exact integers are <= 10^15.
// Exact powers of ten are <= 10^22.
if d.nd > 15 {
- return;
+ return
}
switch {
case d.dp == d.nd: // int
@@ -280,7 +280,7 @@ func decimalAtof32(neg bool, d *decimal, trunc bool) (f float32, ok bool) {
// Exact integers are <= 10^7.
// Exact powers of ten are <= 10^10.
if d.nd > 7 {
- return;
+ return
}
switch {
case d.dp == d.nd: // int
@@ -322,17 +322,17 @@ func decimalAtof32(neg bool, d *decimal, trunc bool) (f float32, ok bool) {
func Atof32(s string) (f float32, err os.Error) {
neg, d, trunc, ok := stringToDecimal(s);
if !ok {
- return 0, &NumError{s, os.EINVAL};
+ return 0, &NumError{s, os.EINVAL}
}
if optimize {
if f, ok := decimalAtof32(neg, d, trunc); ok {
- return f, nil;
+ return f, nil
}
}
b, ovf := decimalToFloatBits(neg, d, trunc, &float32info);
f = math.Float32frombits(uint32(b));
if ovf {
- err = &NumError{s, os.ERANGE};
+ err = &NumError{s, os.ERANGE}
}
return f, err;
}
@@ -343,17 +343,17 @@ func Atof32(s string) (f float32, err os.Error) {
func Atof64(s string) (f float64, err os.Error) {
neg, d, trunc, ok := stringToDecimal(s);
if !ok {
- return 0, &NumError{s, os.EINVAL};
+ return 0, &NumError{s, os.EINVAL}
}
if optimize {
if f, ok := decimalAtof64(neg, d, trunc); ok {
- return f, nil;
+ return f, nil
}
}
b, ovf := decimalToFloatBits(neg, d, trunc, &float64info);
f = math.Float64frombits(b);
if ovf {
- err = &NumError{s, os.ERANGE};
+ err = &NumError{s, os.ERANGE}
}
return f, err;
}
diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go
index a59fb78b4..c9b374d35 100644
--- a/src/pkg/strconv/atof_test.go
+++ b/src/pkg/strconv/atof_test.go
@@ -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}
}
}
}
@@ -111,7 +111,7 @@ func testAtof(t *testing.T, opt bool) {
outs := Ftoa64(out, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("Atof64(%v) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
if float64(float32(out)) == out {
@@ -119,7 +119,7 @@ func testAtof(t *testing.T, opt bool) {
outs := Ftoa32(out32, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("Atof32(%v) = %v, %v want %v, %v # %v\n",
- test.in, out32, err, test.out, test.err, out);
+ test.in, out32, err, test.out, test.err, out)
}
}
@@ -128,7 +128,7 @@ func testAtof(t *testing.T, opt bool) {
outs := Ftoa(outf, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("Ftoa(%v) = %v, %v want %v, %v # %v\n",
- test.in, outf, err, test.out, test.err, out);
+ test.in, outf, err, test.out, test.err, out)
}
}
}
diff --git a/src/pkg/strconv/atoi.go b/src/pkg/strconv/atoi.go
index eddda20a5..2194821f3 100644
--- a/src/pkg/strconv/atoi.go
+++ b/src/pkg/strconv/atoi.go
@@ -17,7 +17,7 @@ func (e *NumError) String() string { return "parsing " + e.Num + ": " + e.Error.
func computeIntsize() uint {
siz := uint(8);
for 1<<siz != 0 {
- siz *= 2;
+ siz *= 2
}
return siz;
}
@@ -27,7 +27,7 @@ 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 0
}
return (1<<64 - 1)/uint64(base) + 1;
}
@@ -62,9 +62,9 @@ func Btoui64(s string, b int) (n uint64, err os.Error) {
goto Error;
}
case s[0] == '0':
- b = 8;
+ b = 8
default:
- b = 10;
+ b = 10
}
default:
@@ -79,11 +79,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;
@@ -125,7 +125,7 @@ Error:
// Atoui64 returns err == os.EINVAL if s is empty or contains invalid digits.
// It returns err == os.ERANGE if s cannot be represented by a uint64.
func Atoui64(s string) (n uint64, err os.Error) {
- return Btoui64(s, 10);
+ return Btoui64(s, 10)
}
// Btoi64 is like Btoui64 but allows signed numbers and
@@ -133,14 +133,14 @@ func Atoui64(s string) (n uint64, err os.Error) {
func Btoi64(s string, base int) (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)];
@@ -154,14 +154,14 @@ func Btoi64(s string, base int) (i int64, err os.Error) {
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;
}
@@ -175,11 +175,11 @@ func Atoi64(s string) (i int64, err os.Error) { return Btoi64(s, 10) }
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;
}
@@ -188,12 +188,12 @@ func Atoui(s string) (i uint, err os.Error) {
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};
}
diff --git a/src/pkg/strconv/atoi_test.go b/src/pkg/strconv/atoi_test.go
index a3c61fcb8..da9de577b 100644
--- a/src/pkg/strconv/atoi_test.go
+++ b/src/pkg/strconv/atoi_test.go
@@ -153,37 +153,37 @@ 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 btoui64tests {
test := &btoui64tests[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 btoi64tests {
test := &btoi64tests[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}
}
}
}
@@ -194,7 +194,7 @@ func TestAtoui64(t *testing.T) {
out, err := Atoui64(test.in);
if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui64(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
@@ -205,7 +205,7 @@ func TestBtoui64(t *testing.T) {
out, err := Btoui64(test.in, 0);
if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Btoui64(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
@@ -216,7 +216,7 @@ func TestAtoi64(t *testing.T) {
out, err := Atoi64(test.in);
if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi64(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
@@ -227,7 +227,7 @@ func TestBtoi64(t *testing.T) {
out, err := Btoi64(test.in, 0);
if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("Btoi64(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
@@ -240,7 +240,7 @@ func TestAtoui(t *testing.T) {
out, err := Atoui(test.in);
if test.out != uint32(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
case 64:
@@ -249,7 +249,7 @@ func TestAtoui(t *testing.T) {
out, err := Atoui(test.in);
if test.out != uint64(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoui(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
@@ -263,7 +263,7 @@ func TestAtoi(t *testing.T) {
out, err := Atoi(test.in);
if test.out != int32(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
case 64:
@@ -272,7 +272,7 @@ func TestAtoi(t *testing.T) {
out, err := Atoi(test.in);
if test.out != int64(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("Atoi(%q) = %v, %v want %v, %v\n",
- test.in, out, err, test.out, test.err);
+ test.in, out, err, test.out, test.err)
}
}
}
diff --git a/src/pkg/strconv/decimal.go b/src/pkg/strconv/decimal.go
index 1f0205ca3..898a77dc7 100644
--- a/src/pkg/strconv/decimal.go
+++ b/src/pkg/strconv/decimal.go
@@ -24,17 +24,17 @@ type decimal struct {
func (a *decimal) String() string {
n := 10 + a.nd;
if a.dp > 0 {
- n += a.dp;
+ n += a.dp
}
if a.dp < 0 {
- n += -a.dp;
+ n += -a.dp
}
buf := make([]byte, n);
w := 0;
switch {
case a.nd == 0:
- return "0";
+ return "0"
case a.dp <= 0:
// zeros fill space between decimal point and digits
@@ -62,14 +62,14 @@ func (a *decimal) String() string {
func copy(dst []byte, src []byte) int {
for i := 0; i < len(dst); i++ {
- dst[i] = src[i];
+ dst[i] = src[i]
}
return len(dst);
}
func digitZero(dst []byte) int {
for i := 0; i < len(dst); i++ {
- dst[i] = '0';
+ dst[i] = '0'
}
return len(dst);
}
@@ -79,10 +79,10 @@ func digitZero(dst []byte) int {
// independent of the number of digits.)
func trim(a *decimal) {
for a.nd > 0 && a.d[a.nd - 1] == '0' {
- a.nd--;
+ a.nd--
}
if a.nd == 0 {
- a.dp = 0;
+ a.dp = 0
}
}
@@ -230,10 +230,10 @@ var leftcheats = []leftCheat{
func prefixIsLessThan(b []byte, s string) bool {
for i := 0; i < len(s); i++ {
if i >= len(b) {
- return true;
+ return true
}
if b[i] != s[i] {
- return b[i] < s[i];
+ return b[i] < s[i]
}
}
return false;
@@ -243,7 +243,7 @@ func prefixIsLessThan(b []byte, s string) bool {
func leftShift(a *decimal, k uint) {
delta := leftcheats[k].delta;
if prefixIsLessThan(a.d[0 : a.nd], leftcheats[k].cutoff) {
- delta--;
+ delta--
}
r := a.nd; // read index
@@ -299,10 +299,10 @@ func (a *decimal) Shift(k int) *decimal {
// If we chop a at nd digits, should we round up?
func shouldRoundUp(a *decimal, nd int) bool {
if nd <= 0 || nd >= a.nd {
- return false;
+ return false
}
if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even
- return (a.d[nd-1] - '0')%2 != 0;
+ return (a.d[nd-1] - '0')%2 != 0
}
// not halfway - digit tells all
return a.d[nd] >= '5';
@@ -312,10 +312,10 @@ func shouldRoundUp(a *decimal, nd int) bool {
// Returns receiver for convenience.
func (a *decimal) Round(nd int) *decimal {
if nd <= 0 || nd >= a.nd {
- return a;
+ return a
}
if shouldRoundUp(a, nd) {
- return a.RoundUp(nd);
+ return a.RoundUp(nd)
}
return a.RoundDown(nd);
}
@@ -324,7 +324,7 @@ func (a *decimal) Round(nd int) *decimal {
// Returns receiver for convenience.
func (a *decimal) RoundDown(nd int) *decimal {
if nd <= 0 || nd >= a.nd {
- return a;
+ return a
}
a.nd = nd;
trim(a);
@@ -335,7 +335,7 @@ func (a *decimal) RoundDown(nd int) *decimal {
// Returns receiver for convenience.
func (a *decimal) RoundUp(nd int) *decimal {
if nd <= 0 || nd >= a.nd {
- return a;
+ return a
}
// round up
@@ -360,18 +360,18 @@ func (a *decimal) RoundUp(nd int) *decimal {
// No guarantees about overflow.
func (a *decimal) RoundedInteger() uint64 {
if a.dp > 20 {
- return 0xFFFFFFFFFFFFFFFF;
+ return 0xFFFFFFFFFFFFFFFF
}
var i int;
n := uint64(0);
for i = 0; i < a.dp && i < a.nd; i++ {
- n = n*10 + uint64(a.d[i] - '0');
+ n = n*10 + uint64(a.d[i] - '0')
}
for ; i < a.dp; i++ {
- n *= 10;
+ n *= 10
}
if shouldRoundUp(a, a.dp) {
- n++;
+ n++
}
return n;
}
diff --git a/src/pkg/strconv/decimal_test.go b/src/pkg/strconv/decimal_test.go
index 1ac4d5e27..b86eec683 100644
--- a/src/pkg/strconv/decimal_test.go
+++ b/src/pkg/strconv/decimal_test.go
@@ -35,7 +35,7 @@ func TestDecimalShift(t *testing.T) {
s := NewDecimal(test.i).Shift(test.shift).String();
if s != test.out {
t.Errorf("Decimal %v << %v = %v, want %v\n",
- test.i, test.shift, s, test.out);
+ test.i, test.shift, s, test.out)
}
}
}
@@ -71,17 +71,17 @@ func TestDecimalRound(t *testing.T) {
s := NewDecimal(test.i).RoundDown(test.nd).String();
if s != test.down {
t.Errorf("Decimal %v RoundDown %d = %v, want %v\n",
- test.i, test.nd, s, test.down);
+ test.i, test.nd, s, test.down)
}
s = NewDecimal(test.i).Round(test.nd).String();
if s != test.round {
t.Errorf("Decimal %v Round %d = %v, want %v\n",
- test.i, test.nd, s, test.down);
+ test.i, test.nd, s, test.down)
}
s = NewDecimal(test.i).RoundUp(test.nd).String();
if s != test.up {
t.Errorf("Decimal %v RoundUp %d = %v, want %v\n",
- test.i, test.nd, s, test.up);
+ test.i, test.nd, s, test.up)
}
}
}
@@ -111,7 +111,7 @@ func TestDecimalRoundedInteger(t *testing.T) {
int := NewDecimal(test.i).Shift(test.shift).RoundedInteger();
if int != test.int {
t.Errorf("Decimal %v >> %v RoundedInteger = %v, want %v\n",
- test.i, test.shift, int, test.int);
+ test.i, test.shift, int, test.int)
}
}
}
diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go
index 47bf6231f..757041d33 100644
--- a/src/pkg/strconv/fp_test.go
+++ b/src/pkg/strconv/fp_test.go
@@ -16,11 +16,11 @@ import (
func pow2(i int) float64 {
switch {
case i < 0:
- return 1/pow2(-i);
+ return 1/pow2(-i)
case i == 0:
- return 1;
+ return 1
case i == 1:
- return 2;
+ return 2
}
return pow2(i/2)*pow2(i - i/2);
}
@@ -32,7 +32,7 @@ func myatof64(s string) (f float64, ok bool) {
if len(a) == 2 {
n, err := strconv.Atoi64(a[0]);
if err != nil {
- return 0, false;
+ return 0, false
}
e, err1 := strconv.Atoi(a[1]);
if err1 != nil {
@@ -64,7 +64,7 @@ func myatof64(s string) (f float64, ok bool) {
}
f1, err := strconv.Atof64(s);
if err != nil {
- return 0, false;
+ return 0, false
}
return f1, true;
}
@@ -88,7 +88,7 @@ func myatof32(s string) (f float32, ok bool) {
}
f1, err1 := strconv.Atof32(s);
if err1 != nil {
- return 0, false;
+ return 0, false
}
return f1, true;
}
@@ -96,7 +96,7 @@ func myatof32(s string) (f float32, ok bool) {
func TestFp(t *testing.T) {
f, err := os.Open("testfp.txt", os.O_RDONLY, 0);
if err != nil {
- panicln("testfp: open testfp.txt:", err.String());
+ panicln("testfp: open testfp.txt:", err.String())
}
defer f.Close();
@@ -106,15 +106,15 @@ func TestFp(t *testing.T) {
for {
line, err2 := b.ReadString('\n');
if err2 == os.EOF {
- break;
+ break
}
if err2 != nil {
- panicln("testfp: read testfp.txt:", err2.String());
+ panicln("testfp: read testfp.txt:", err2.String())
}
line = line[0 : len(line)-1];
lineno++;
if len(line) == 0 || line[0] == '#' {
- continue;
+ continue
}
a := strings.Split(line, " ", 0);
if len(a) != 4 {
@@ -143,7 +143,7 @@ func TestFp(t *testing.T) {
}
if s != a[3] {
t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ",
- "want ", a[3], " got ", s);
+ "want ", a[3], " got ", s)
}
}
}
diff --git a/src/pkg/strconv/ftoa.go b/src/pkg/strconv/ftoa.go
index f10d07163..d31f44142 100644
--- a/src/pkg/strconv/ftoa.go
+++ b/src/pkg/strconv/ftoa.go
@@ -28,7 +28,7 @@ func floatsize() int {
// is too small for a float32.
var f float = 1e-35;
if f*f == 0 {
- return 32;
+ return 32
}
return 64;
}
@@ -56,18 +56,18 @@ var FloatSize = floatsize()
// because correct rounding and the number of digits
// needed to identify f depend on the precision of the representation.
func Ftoa32(f float32, fmt byte, prec int) string {
- return genericFtoa(uint64(math.Float32bits(f)), fmt, prec, &float32info);
+ return genericFtoa(uint64(math.Float32bits(f)), fmt, prec, &float32info)
}
// Ftoa64 is like Ftoa32 but converts a 64-bit floating-point number.
func Ftoa64(f float64, fmt byte, prec int) string {
- return genericFtoa(math.Float64bits(f), fmt, prec, &float64info);
+ return genericFtoa(math.Float64bits(f), fmt, prec, &float64info)
}
// Ftoa behaves as Ftoa32 or Ftoa64, depending on the size of the float type.
func Ftoa(f float, fmt byte, prec int) string {
if FloatSize == 32 {
- return Ftoa32(float32(f), fmt, prec);
+ return Ftoa32(float32(f), fmt, prec)
}
return Ftoa64(float64(f), fmt, prec);
}
@@ -81,26 +81,26 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
case 1 << flt.expbits - 1:
// Inf, NaN
if mant != 0 {
- return "NaN";
+ return "NaN"
}
if neg {
- return "-Inf";
+ return "-Inf"
}
return "+Inf";
case 0:
// denormalized
- exp++;
+ exp++
default:
// add implicit top bit
- mant |= uint64(1) << flt.mantbits;
+ mant |= uint64(1) << flt.mantbits
}
exp += flt.bias;
// Pick off easy binary format.
if fmt == 'b' {
- return fmtB(neg, mant, exp, flt);
+ return fmtB(neg, mant, exp, flt)
}
// Create exact decimal representation.
@@ -117,21 +117,21 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
roundShortest(d, mant, exp, flt);
switch fmt {
case 'e', 'E':
- prec = d.nd - 1;
+ prec = d.nd - 1
case 'f':
- prec = max(d.nd - d.dp, 0);
+ prec = max(d.nd - d.dp, 0)
case 'g', 'G':
- prec = d.nd;
+ prec = d.nd
}
} else {
switch fmt {
case 'e', 'E':
- d.Round(prec+1);
+ d.Round(prec+1)
case 'f':
- d.Round(d.dp + prec);
+ d.Round(d.dp + prec)
case 'g', 'G':
if prec == 0 {
- prec = 1;
+ prec = 1
}
d.Round(prec);
}
@@ -139,24 +139,24 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
switch fmt {
case 'e', 'E':
- return fmtE(neg, d, prec, fmt);
+ return fmtE(neg, d, prec, fmt)
case 'f':
- return fmtF(neg, d, prec);
+ return fmtF(neg, d, prec)
case 'g', 'G':
// trailing zeros are removed.
if prec > d.nd {
- prec = d.nd;
+ prec = d.nd
}
// %e is used if the exponent from the conversion
// is less than -4 or greater than or equal to the precision.
// if precision was the shortest possible, use precision 6 for this decision.
eprec := prec;
if shortest {
- eprec = 6;
+ eprec = 6
}
exp := d.dp - 1;
if exp < -4 || exp >= eprec {
- return fmtE(neg, d, prec-1, fmt+'e'-'g');
+ return fmtE(neg, d, prec-1, fmt+'e'-'g')
}
return fmtF(neg, d, max(prec - d.dp, 0));
}
@@ -216,15 +216,15 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
for i := 0; i < d.nd; i++ {
var l, m, u byte; // lower, middle, upper digits
if i < lower.nd {
- l = lower.d[i];
+ l = lower.d[i]
} else {
- l = '0';
+ l = '0'
}
m = d.d[i];
if i < upper.nd {
- u = upper.d[i];
+ u = upper.d[i]
} else {
- u = '0';
+ u = '0'
}
// Okay to round down (truncate) if lower has a different digit
@@ -264,9 +264,9 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
// first digit
if d.nd == 0 {
- buf[w] = '0';
+ buf[w] = '0'
} else {
- buf[w] = d.d[0];
+ buf[w] = d.d[0]
}
w++;
@@ -276,9 +276,9 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
w++;
for i := 0; i < prec; i++ {
if 1+i < d.nd {
- buf[w] = d.d[1+i];
+ buf[w] = d.d[1+i]
} else {
- buf[w] = '0';
+ buf[w] = '0'
}
w++;
}
@@ -289,13 +289,13 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
w++;
exp := d.dp - 1;
if d.nd == 0 { // special case: 0 has exponent 0
- exp = 0;
+ exp = 0
}
if exp < 0 {
buf[w] = '-';
exp = -exp;
} else {
- buf[w] = '+';
+ buf[w] = '+'
}
w++;
@@ -303,7 +303,7 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string {
// count digits
n := 0;
for e := exp; e > 0; e /= 10 {
- n++;
+ n++
}
// leading zeros
for i := n; i < 2; i++ {
@@ -354,9 +354,9 @@ func fmtF(neg bool, d *decimal, prec int) string {
w++;
for i := 0; i < prec; i++ {
if d.dp + i < 0 || d.dp + i >= d.nd {
- buf[w] = '0';
+ buf[w] = '0'
} else {
- buf[w] = d.d[d.dp + i];
+ buf[w] = d.d[d.dp + i]
}
w++;
}
@@ -402,7 +402,7 @@ func fmtB(neg bool, mant uint64, exp int, flt *floatInfo) string {
func max(a, b int) int {
if a > b {
- return a;
+ return a
}
return b;
}
diff --git a/src/pkg/strconv/ftoa_test.go b/src/pkg/strconv/ftoa_test.go
index 7475ac6b3..20548e384 100644
--- a/src/pkg/strconv/ftoa_test.go
+++ b/src/pkg/strconv/ftoa_test.go
@@ -101,18 +101,18 @@ var ftoatests = []ftoaTest{
func TestFtoa(t *testing.T) {
if FloatSize != 32 {
- panic("floatsize: ", FloatSize);
+ panic("floatsize: ", FloatSize)
}
for i := 0; i < len(ftoatests); i++ {
test := &ftoatests[i];
s := Ftoa64(test.f, test.fmt, test.prec);
if s != test.s {
- t.Error("test", test.f, string(test.fmt), test.prec, "want", test.s, "got", s);
+ t.Error("test", test.f, string(test.fmt), test.prec, "want", test.s, "got", s)
}
if float64(float32(test.f)) == test.f && test.fmt != 'b' {
s := Ftoa32(float32(test.f), test.fmt, test.prec);
if s != test.s {
- t.Error("test32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s);
+ t.Error("test32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s)
}
}
}
diff --git a/src/pkg/strconv/itoa.go b/src/pkg/strconv/itoa.go
index b1025d4a2..65d60d79c 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.
@@ -26,11 +26,11 @@ func Uitob64(u uint64, base uint) string {
// 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 {
- return "-" + Uitob64(-uint64(i), base);
+ return "-" + Uitob64(-uint64(i), base)
}
return Uitob64(uint64(i), base);
}
diff --git a/src/pkg/strconv/itoa_test.go b/src/pkg/strconv/itoa_test.go
index b8e7ee3ab..f48a5342a 100644
--- a/src/pkg/strconv/itoa_test.go
+++ b/src/pkg/strconv/itoa_test.go
@@ -62,14 +62,14 @@ func TestItoa(t *testing.T) {
s := Itob64(test.in, test.base);
if s != test.out {
t.Errorf("Itob64(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
if test.in >= 0 {
s := Uitob64(uint64(test.in), test.base);
if s != test.out {
t.Errorf("Uitob64(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
}
@@ -77,14 +77,14 @@ func TestItoa(t *testing.T) {
s := Itob(int(test.in), test.base);
if s != test.out {
t.Errorf("Itob(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
if test.in >= 0 {
s := Uitob(uint(test.in), test.base);
if s != test.out {
t.Errorf("Uitob(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
}
}
@@ -93,14 +93,14 @@ func TestItoa(t *testing.T) {
s := Itoa64(test.in);
if s != test.out {
t.Errorf("Itoa64(%v) = %v want %v\n",
- test.in, s, test.out);
+ test.in, s, test.out)
}
if test.in >= 0 {
s := Uitob64(uint64(test.in), test.base);
if s != test.out {
t.Errorf("Uitob64(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
}
@@ -108,14 +108,14 @@ func TestItoa(t *testing.T) {
s := Itoa(int(test.in));
if s != test.out {
t.Errorf("Itoa(%v) = %v want %v\n",
- test.in, s, test.out);
+ test.in, s, test.out)
}
if test.in >= 0 {
s := Uitoa(uint(test.in));
if s != test.out {
t.Errorf("Uitoa(%v) = %v want %v\n",
- test.in, s, test.out);
+ test.in, s, test.out)
}
}
}
@@ -142,14 +142,14 @@ func TestUitoa(t *testing.T) {
s := Uitob64(test.in, test.base);
if s != test.out {
t.Errorf("Uitob64(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
if uint64(uint(test.in)) == test.in {
s := Uitob(uint(test.in), test.base);
if s != test.out {
t.Errorf("Uitob(%v, %v) = %v want %v\n",
- test.in, test.base, s, test.out);
+ test.in, test.base, s, test.out)
}
}
@@ -157,14 +157,14 @@ func TestUitoa(t *testing.T) {
s := Uitoa64(test.in);
if s != test.out {
t.Errorf("Uitoa64(%v) = %v want %v\n",
- test.in, s, test.out);
+ test.in, s, test.out)
}
if uint64(uint(test.in)) == test.in {
s := Uitoa(uint(test.in));
if s != test.out {
t.Errorf("Uitoa(%v) = %v want %v\n",
- test.in, s, test.out);
+ test.in, s, test.out)
}
}
}
diff --git a/src/pkg/strconv/quote.go b/src/pkg/strconv/quote.go
index 807b25ace..c655e2f8c 100644
--- a/src/pkg/strconv/quote.go
+++ b/src/pkg/strconv/quote.go
@@ -24,41 +24,41 @@ func Quote(s string) string {
for ; len(s) > 0; s = s[1:len(s)] {
switch c := s[0]; {
case c == '"':
- buf.WriteString(`\"`);
+ buf.WriteString(`\"`)
case c == '\\':
- buf.WriteString(`\\`);
+ buf.WriteString(`\\`)
case ' ' <= c && c <= '~':
- buf.WriteString(string(c));
+ buf.WriteString(string(c))
case c == '\a':
- buf.WriteString(`\a`);
+ buf.WriteString(`\a`)
case c == '\b':
- buf.WriteString(`\b`);
+ buf.WriteString(`\b`)
case c == '\f':
- buf.WriteString(`\f`);
+ buf.WriteString(`\f`)
case c == '\n':
- buf.WriteString(`\n`);
+ buf.WriteString(`\n`)
case c == '\r':
- buf.WriteString(`\r`);
+ buf.WriteString(`\r`)
case c == '\t':
- buf.WriteString(`\t`);
+ buf.WriteString(`\t`)
case c == '\v':
- buf.WriteString(`\v`);
+ buf.WriteString(`\v`)
case c >= utf8.RuneSelf && utf8.FullRuneInString(s):
r, size := utf8.DecodeRuneInString(s);
if r == utf8.RuneError && size == 1 {
- goto EscX;
+ goto EscX
}
s = s[size-1 : len(s)]; // next iteration will slice off 1 more
if r < 0x10000 {
buf.WriteString(`\u`);
for j := uint(0); j < 4; j++ {
- buf.WriteByte(lowerhex[(r>>(12 - 4*j))&0xF]);
+ buf.WriteByte(lowerhex[(r>>(12 - 4*j))&0xF])
}
} else {
buf.WriteString(`\U`);
for j := uint(0); j < 8; j++ {
- buf.WriteByte(lowerhex[(r>>(28 - 4*j))&0xF]);
+ buf.WriteByte(lowerhex[(r>>(28 - 4*j))&0xF])
}
}
@@ -78,7 +78,7 @@ func Quote(s string) string {
func CanBackquote(s string) bool {
for i := 0; i < len(s); i++ {
if (s[i] < ' ' && s[i] != '\t') || s[i] == '`' {
- return false;
+ return false
}
}
return true;
@@ -88,11 +88,11 @@ 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;
}
@@ -120,7 +120,7 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
r, size := utf8.DecodeRuneInString(s);
return r, true, s[size:len(s)], nil;
case c != '\\':
- return int(s[0]), false, s[1:len(s)], nil;
+ return int(s[0]), false, s[1:len(s)], nil
}
// hard case: c is backslash
@@ -133,28 +133,28 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
switch c {
case 'a':
- value = '\a';
+ value = '\a'
case 'b':
- value = '\b';
+ value = '\b'
case 'f':
- value = '\f';
+ value = '\f'
case 'n':
- value = '\n';
+ value = '\n'
case 'r':
- value = '\r';
+ value = '\r'
case 't':
- value = '\t';
+ value = '\t'
case 'v':
- value = '\v';
+ value = '\v'
case 'x', 'u', 'U':
n := 0;
switch c {
case 'x':
- n = 2;
+ n = 2
case 'u':
- n = 4;
+ n = 4
case 'U':
- n = 8;
+ n = 8
}
v := 0;
if len(s) < n {
@@ -190,7 +190,7 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
for j := 0; j < 2; j++ { // one digit already; two more
x := int(s[j])-'0';
if x < 0 || x > 7 {
- return;
+ return
}
v = (v<<3)|x;
}
@@ -201,7 +201,7 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
}
value = v;
case '\\':
- value = '\\';
+ value = '\\'
case '\'', '"':
if c != quote {
err = os.EINVAL;
@@ -224,39 +224,39 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
func Unquote(s string) (t string, err os.Error) {
n := len(s);
if n < 2 {
- return "", os.EINVAL;
+ return "", os.EINVAL
}
quote := s[0];
if quote != s[n-1] {
- return "", os.EINVAL;
+ return "", os.EINVAL
}
s = s[1 : n-1];
if quote == '`' {
if strings.Index(s, "`") >= 0 {
- return "", os.EINVAL;
+ return "", os.EINVAL
}
return s, nil;
}
if quote != '"' && quote != '\'' {
- return "", err;
+ return "", err
}
var buf bytes.Buffer;
for len(s) > 0 {
c, multibyte, ss, err := UnquoteChar(s, quote);
if err != nil {
- return "", err;
+ return "", err
}
s = ss;
if c < utf8.RuneSelf || !multibyte {
- buf.WriteByte(byte(c));
+ buf.WriteByte(byte(c))
} else {
- buf.WriteString(string(c));
+ buf.WriteString(string(c))
}
if quote == '\'' && len(s) != 0 {
// single-quoted must be single character
- return "", os.EINVAL;
+ return "", os.EINVAL
}
}
return buf.String(), nil;
diff --git a/src/pkg/strconv/quote_test.go b/src/pkg/strconv/quote_test.go
index 7f8391491..3c42d3971 100644
--- a/src/pkg/strconv/quote_test.go
+++ b/src/pkg/strconv/quote_test.go
@@ -28,7 +28,7 @@ func TestQuote(t *testing.T) {
for i := 0; i < len(quotetests); i++ {
tt := quotetests[i];
if out := Quote(tt.in); out != tt.out {
- t.Errorf("Quote(%s) = %s, want %s", tt.in, out, tt.out);
+ t.Errorf("Quote(%s) = %s, want %s", tt.in, out, tt.out)
}
}
}
@@ -83,7 +83,7 @@ func TestCanBackquote(t *testing.T) {
for i := 0; i < len(canbackquotetests); i++ {
tt := canbackquotetests[i];
if out := CanBackquote(tt.in); out != tt.out {
- t.Errorf("CanBackquote(%q) = %v, want %v", tt.in, out, tt.out);
+ t.Errorf("CanBackquote(%q) = %v, want %v", tt.in, out, tt.out)
}
}
}
@@ -149,7 +149,7 @@ func TestUnquote(t *testing.T) {
for i := 0; i < len(unquotetests); i++ {
tt := unquotetests[i];
if out, err := Unquote(tt.in); err != nil && out != tt.out {
- t.Errorf("Unquote(%#q) = %q, %v want %q, nil", tt.in, out, err, tt.out);
+ t.Errorf("Unquote(%#q) = %q, %v want %q, nil", tt.in, out, err, tt.out)
}
}
@@ -157,14 +157,14 @@ func TestUnquote(t *testing.T) {
for i := 0; i < len(quotetests); i++ {
tt := quotetests[i];
if in, err := Unquote(tt.out); in != tt.in {
- t.Errorf("Unquote(%#q) = %q, %v, want %q, nil", tt.out, in, err, tt.in);
+ t.Errorf("Unquote(%#q) = %q, %v, want %q, nil", tt.out, in, err, tt.in)
}
}
for i := 0; i < len(misquoted); i++ {
s := misquoted[i];
if out, err := Unquote(s); out != "" || err != os.EINVAL {
- t.Errorf("Unquote(%#q) = %q, %v want %q, %v", s, out, err, "", os.EINVAL);
+ t.Errorf("Unquote(%#q) = %q, %v want %q, %v", s, out, err, "", os.EINVAL)
}
}
}