diff options
| author | Russ Cox <rsc@golang.org> | 2009-09-15 09:41:59 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-09-15 09:41:59 -0700 |
| commit | ca6a0fee1b3f68ab4e9f8e1c7fbe80f178e68c09 (patch) | |
| tree | 46eac6aefe26f0b9056bff646d960bcba3d076cf /src/pkg/bytes | |
| parent | 1a3198907bf18ac961762024cf2a27581e6be6c3 (diff) | |
| download | go-ca6a0fee1b3f68ab4e9f8e1c7fbe80f178e68c09.tar.xz | |
more "declared and not used".
the last round omitted := range and only
checked 1 out of N vars in a multi-var :=
R=r
OCL=34624
CL=34638
Diffstat (limited to 'src/pkg/bytes')
| -rw-r--r-- | src/pkg/bytes/buffer_test.go | 2 | ||||
| -rw-r--r-- | src/pkg/bytes/bytes.go | 15 | ||||
| -rw-r--r-- | src/pkg/bytes/bytes_test.go | 4 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/pkg/bytes/buffer_test.go b/src/pkg/bytes/buffer_test.go index 4d3fca8727..bb6593774a 100644 --- a/src/pkg/bytes/buffer_test.go +++ b/src/pkg/bytes/buffer_test.go @@ -164,7 +164,7 @@ func TestMixedReadsAndWrites(t *testing.T) { rlen := rand.Intn(len(data)); fub := make([]byte, rlen); - n, err := buf.Read(fub); + n, _ := buf.Read(fub); s = s[n : len(s)]; } empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len())); diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index d4eb4c7d99..30ac4580b5 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -190,8 +190,8 @@ func Map(mapping func(rune int) int, s []byte) []byte { maxbytes := len(s); // length of b nbytes := 0; // number of bytes encoded in b b := make([]byte, maxbytes); - for wid, i := 0, 0; i < len(s); i += wid { - wid = 1; + for i := 0; i < len(s); { + wid := 1; rune := int(s[i]); if rune < utf8.RuneSelf { rune = mapping(rune); @@ -209,6 +209,7 @@ func Map(mapping func(rune int) int, s []byte) []byte { b = nb; } nbytes += utf8.EncodeRune(rune, b[nbytes:maxbytes]); + i += wid; } return b[0:nbytes]; } @@ -232,8 +233,8 @@ func Title(s []byte) []byte { // removed, as defined by Unicode. func TrimSpace(s []byte) []byte { start, end := 0, len(s); - for wid := 0; start < end; start += wid { - wid = 1; + for start < end { + wid := 1; rune := int(s[start]); if rune >= utf8.RuneSelf { rune, wid = utf8.DecodeRune(s[start:end]) @@ -241,9 +242,10 @@ func TrimSpace(s []byte) []byte { if !unicode.IsSpace(rune) { break; } + start += wid; } - for wid := 0; start < end; end -= wid { - wid = 1; + for start < end { + wid := 1; rune := int(s[end-1]); if rune >= utf8.RuneSelf { // Back up carefully looking for beginning of rune. Mustn't pass start. @@ -257,6 +259,7 @@ func TrimSpace(s []byte) []byte { if !unicode.IsSpace(rune) { break; } + end -= wid; } return s[start:end]; } diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 8443480e56..df4d4c2d0c 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -216,7 +216,7 @@ func Bytes(s string) []byte { // Execute f on each test case. funcName should be the name of f; it's used // in failure reports. func runStringTests(t *testing.T, f func([]byte) []byte, funcName string, testCases []StringTest) { - for i, tc := range testCases { + for _, tc := range testCases { actual := string(f(Bytes(tc.in))); if actual != tc.out { t.Errorf("%s(%q) = %q; want %q", funcName, tc.in, actual, tc.out); @@ -275,7 +275,7 @@ var addtests = []AddTest { } func TestAdd(t *testing.T) { - for i, test := range addtests { + for _, test := range addtests { b := make([]byte, len(test.s), test.cap); for i := 0; i < len(test.s); i++ { b[i] = test.s[i] |
