diff options
| author | Robert Griesemer <gri@golang.org> | 2009-11-09 21:23:52 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-11-09 21:23:52 -0800 |
| commit | 3bb0032cd6187ca1f42b68599b94036cb6b7e054 (patch) | |
| tree | 3293f2b050aa0a83e6b3deb4240f4eab5ef571fd /src/pkg/strings | |
| parent | baba292998286e5d9011705a9b4173a2ec99c5e0 (diff) | |
| download | go-3bb0032cd6187ca1f42b68599b94036cb6b7e054.tar.xz | |
- replaced gofmt expression formatting algorithm with
rsc's algorithm
- applied gofmt -w misc src
- partial CL (last chunk)
R=rsc, r
http://go/go-review/1024041
Diffstat (limited to 'src/pkg/strings')
| -rw-r--r-- | src/pkg/strings/strings.go | 20 | ||||
| -rw-r--r-- | src/pkg/strings/strings_test.go | 8 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 5e1b5b35cc..055d7d1e99 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -41,9 +41,9 @@ func Count(s, sep string) int { c := sep[0]; n := 0; for i := 0; i+len(sep) <= len(s); i++ { - if s[i] == c && (len(sep) == 1 || s[i : i+len(sep)] == sep) { + if s[i] == c && (len(sep) == 1 || s[i:i+len(sep)] == sep) { n++; - i += len(sep)-1; + i += len(sep) - 1; } } return n; @@ -57,7 +57,7 @@ func Index(s, sep string) int { } c := sep[0]; for i := 0; i+n <= len(s); i++ { - if s[i] == c && (n == 1 || s[i : i+n] == sep) { + if s[i] == c && (n == 1 || s[i:i+n] == sep) { return i } } @@ -71,8 +71,8 @@ func LastIndex(s, sep string) int { return len(s) } c := sep[0]; - for i := len(s)-n; i >= 0; i-- { - if s[i] == c && (n == 1 || s[i : i+n] == sep) { + for i := len(s) - n; i >= 0; i-- { + if s[i] == c && (n == 1 || s[i:i+n] == sep) { return i } } @@ -93,11 +93,11 @@ func genSplit(s, sep string, sepSave, n int) []string { a := make([]string, n); na := 0; for i := 0; i+len(sep) <= len(s) && na+1 < n; i++ { - if s[i] == c && (len(sep) == 1 || s[i : i+len(sep)] == sep) { + if s[i] == c && (len(sep) == 1 || s[i:i+len(sep)] == sep) { a[na] = s[start : i+sepSave]; na++; - start = i+len(sep); - i += len(sep)-1; + start = i + len(sep); + i += len(sep) - 1; } } a[na] = s[start:len(s)]; @@ -125,7 +125,7 @@ func Join(a []string, sep string) string { if len(a) == 1 { return a[0] } - n := len(sep)*(len(a)-1); + n := len(sep) * (len(a) - 1); for i := 0; i < len(a); i++ { n += len(a[i]) } @@ -156,7 +156,7 @@ func HasPrefix(s, prefix string) bool { // HasSuffix tests whether the string s ends with suffix. func HasSuffix(s, suffix string) bool { - return len(s) >= len(suffix) && s[len(s)-len(suffix) : len(s)] == suffix + return len(s) >= len(suffix) && s[len(s)-len(suffix):len(s)] == suffix } // Map returns a copy of the string s with all its characters modified diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index 1aab16eed8..2281458ea2 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -208,7 +208,7 @@ const space = "\t\v\r\f\n\u0085\u00a0\u2000\u3000" var trimSpaceTests = []StringTest{ StringTest{"", ""}, StringTest{"abc", "abc"}, - StringTest{space+"abc"+space, "abc"}, + StringTest{space + "abc" + space, "abc"}, StringTest{" ", ""}, StringTest{" \t\r\n \t\t\r\r\n\n ", ""}, StringTest{" \t\r\n x\t\t\r\r\n\n ", "x"}, @@ -272,7 +272,7 @@ func equal(m string, s1, s2 string, t *testing.T) bool { func TestCaseConsistency(t *testing.T) { // Make a string of all the runes. - a := make([]int, unicode.MaxRune + 1); + a := make([]int, unicode.MaxRune+1); for i := range a { a[i] = i } @@ -282,10 +282,10 @@ func TestCaseConsistency(t *testing.T) { lower := ToLower(s); // Consistency checks - if n := utf8.RuneCountInString(upper); n != unicode.MaxRune + 1 { + if n := utf8.RuneCountInString(upper); n != unicode.MaxRune+1 { t.Error("rune count wrong in upper:", n) } - if n := utf8.RuneCountInString(lower); n != unicode.MaxRune + 1 { + if n := utf8.RuneCountInString(lower); n != unicode.MaxRune+1 { t.Error("rune count wrong in lower:", n) } if !equal("ToUpper(upper)", ToUpper(upper), upper, t) { |
