aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/strings')
-rw-r--r--src/pkg/strings/strings.go12
-rw-r--r--src/pkg/strings/strings_test.go8
2 files changed, 11 insertions, 9 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index f0f0761576..4883d392cd 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -157,7 +157,7 @@ func Map(mapping func(rune int) int, s string) string {
maxbytes := len(s); // length of b
nbytes := 0; // number of bytes encoded in b
b := make([]byte, maxbytes);
- for i, c := range s {
+ for _, c := range s {
rune := mapping(c);
wid := 1;
if rune >= utf8.RuneSelf {
@@ -196,8 +196,8 @@ func Title(s string) string {
// removed, as defined by Unicode.
func TrimSpace(s string) string {
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.DecodeRuneInString(s[start:end])
@@ -205,9 +205,10 @@ func TrimSpace(s string) string {
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.
@@ -221,6 +222,7 @@ func TrimSpace(s string) string {
if !unicode.IsSpace(rune) {
break;
}
+ end -= wid;
}
return s[start:end];
}
diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go
index 7925ae8352..a01285e95b 100644
--- a/src/pkg/strings/strings_test.go
+++ b/src/pkg/strings/strings_test.go
@@ -66,7 +66,7 @@ var lastIndexTests = []IndexTest {
// Execute f on each test case. funcName should be the name of f; it's used
// in failure reports.
func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, testCases []IndexTest) {
- for i,test := range testCases {
+ for _, test := range testCases {
actual := f(test.s, test.sep);
if actual != test.out {
t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, test.sep, actual, test.out);
@@ -149,7 +149,7 @@ type StringTest struct {
// 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(string) string, funcName string, testCases []StringTest) {
- for i, tc := range testCases {
+ for _, tc := range testCases {
actual := f(tc.in);
if actual != tc.out {
t.Errorf("%s(%q) = %q; want %q", funcName, tc.in, actual, tc.out);
@@ -237,8 +237,8 @@ func equal(m string, s1, s2 string, t *testing.T) bool {
if i > len(e2) {
break
}
- r1, w := utf8.DecodeRuneInString(c1);
- r2, w := utf8.DecodeRuneInString(e2[i]);
+ r1, _ := utf8.DecodeRuneInString(c1);
+ r2, _ := utf8.DecodeRuneInString(e2[i]);
if r1 != r2 {
t.Errorf("%s diff at %d: U+%04X U+%04X", m, i, r1, r2)
}