diff options
| author | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
| commit | 40621d5c0d3f9fc222089967ab1aec44e94b5f78 (patch) | |
| tree | aab097e5a2fcb1b6df8781a044ebfcb1b10a18e5 /src/pkg/strings | |
| parent | 18ccbc69f8ba71a396acba50ecfe5a591f687c78 (diff) | |
| download | go-40621d5c0d3f9fc222089967ab1aec44e94b5f78.tar.xz | |
remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
Diffstat (limited to 'src/pkg/strings')
| -rw-r--r-- | src/pkg/strings/reader.go | 4 | ||||
| -rw-r--r-- | src/pkg/strings/strings.go | 42 | ||||
| -rw-r--r-- | src/pkg/strings/strings_test.go | 36 |
3 files changed, 41 insertions, 41 deletions
diff --git a/src/pkg/strings/reader.go b/src/pkg/strings/reader.go index 55e4d963f7..880bafacdd 100644 --- a/src/pkg/strings/reader.go +++ b/src/pkg/strings/reader.go @@ -13,7 +13,7 @@ type Reader string func (r *Reader) Read(b []byte) (n int, err os.Error) { s := *r; if len(s) == 0 { - return 0, os.EOF; + return 0, os.EOF } for n < len(s) && n < len(b) { b[n] = s[n]; @@ -26,7 +26,7 @@ func (r *Reader) Read(b []byte) (n int, err os.Error) { func (r *Reader) ReadByte() (b byte, err os.Error) { s := *r; if len(s) == 0 { - return 0, os.EOF; + return 0, os.EOF } b = s[0]; *r = s[1:len(s)]; diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 4169f62114..5e1b5b35cc 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -14,7 +14,7 @@ import ( // Invalid UTF-8 sequences become correct encodings of U+FFF8. func explode(s string, n int) []string { if n <= 0 { - n = len(s); + n = len(s) } a := make([]string, n); var size, rune int; @@ -36,7 +36,7 @@ func explode(s string, n int) []string { // Count counts the number of non-overlapping instances of sep in s. func Count(s, sep string) int { if sep == "" { - return utf8.RuneCountInString(s) + 1; + return utf8.RuneCountInString(s) + 1 } c := sep[0]; n := 0; @@ -53,12 +53,12 @@ func Count(s, sep string) int { func Index(s, sep string) int { n := len(sep); if n == 0 { - return 0; + return 0 } c := sep[0]; for i := 0; i+n <= len(s); i++ { if s[i] == c && (n == 1 || s[i : i+n] == sep) { - return i; + return i } } return -1; @@ -68,12 +68,12 @@ func Index(s, sep string) int { func LastIndex(s, sep string) int { n := len(sep); if n == 0 { - return len(s); + 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) { - return i; + return i } } return -1; @@ -83,10 +83,10 @@ func LastIndex(s, sep string) int { // including sepSave bytes of sep in the subarrays. func genSplit(s, sep string, sepSave, n int) []string { if sep == "" { - return explode(s, n); + return explode(s, n) } if n <= 0 { - n = Count(s, sep) + 1; + n = Count(s, sep) + 1 } c := sep[0]; start := 0; @@ -113,21 +113,21 @@ func Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } // If sep is empty, SplitAfter splits s after each UTF-8 sequence. // If n > 0, SplitAfter splits s into at most n substrings; the last substring will be the unsplit remainder. func SplitAfter(s, sep string, n int) []string { - return genSplit(s, sep, len(sep), n); + return genSplit(s, sep, len(sep), n) } // Join concatenates the elements of a to create a single string. The separator string // sep is placed between elements in the resulting string. func Join(a []string, sep string) string { if len(a) == 0 { - return ""; + return "" } if len(a) == 1 { - return a[0]; + return a[0] } n := len(sep)*(len(a)-1); for i := 0; i < len(a); i++ { - n += len(a[i]); + n += len(a[i]) } b := make([]byte, n); @@ -151,12 +151,12 @@ func Join(a []string, sep string) string { // HasPrefix tests whether the string s begins with prefix. func HasPrefix(s, prefix string) bool { - return len(s) >= len(prefix) && s[0:len(prefix)] == prefix; + return len(s) >= len(prefix) && s[0:len(prefix)] == prefix } // 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 @@ -172,14 +172,14 @@ func Map(mapping func(rune int) int, s string) string { rune := mapping(c); wid := 1; if rune >= utf8.RuneSelf { - wid = utf8.RuneLen(rune); + wid = utf8.RuneLen(rune) } if nbytes+wid > maxbytes { // Grow the buffer. maxbytes = maxbytes*2 + utf8.UTFMax; nb := make([]byte, maxbytes); for i, c := range b[0:nbytes] { - nb[i] = c; + nb[i] = c } b = nb; } @@ -205,10 +205,10 @@ func TrimSpace(s string) string { wid := 1; rune := int(s[start]); if rune >= utf8.RuneSelf { - rune, wid = utf8.DecodeRuneInString(s[start:end]); + rune, wid = utf8.DecodeRuneInString(s[start:end]) } if !unicode.IsSpace(rune) { - break; + break } start += wid; } @@ -220,12 +220,12 @@ func TrimSpace(s string) string { for wid = 2; start <= end-wid && !utf8.RuneStart(s[end-wid]); wid++ { } if start > end-wid { // invalid UTF-8 sequence; stop processing - return s[start:end]; + return s[start:end] } rune, wid = utf8.DecodeRuneInString(s[end-wid : end]); } if !unicode.IsSpace(rune) { - break; + break } end -= wid; } @@ -236,7 +236,7 @@ func TrimSpace(s string) string { func Bytes(s string) []byte { b := make([]byte, len(s)); for i := 0; i < len(s); i++ { - b[i] = s[i]; + b[i] = s[i] } return b; } diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index f7aa4dbaec..1aab16eed8 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -13,11 +13,11 @@ import ( func eq(a, b []string) bool { if len(a) != len(b) { - return false; + return false } for i := 0; i < len(a); i++ { if a[i] != b[i] { - return false; + return false } } return true; @@ -69,7 +69,7 @@ func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, tes 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); + t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, test.sep, actual, test.out) } } } @@ -100,7 +100,7 @@ func TestExplode(t *testing.T) { } s := Join(a, ""); if s != tt.s { - t.Errorf(`Join(explode(%q, %d), "") = %q`, tt.s, tt.n, s); + t.Errorf(`Join(explode(%q, %d), "") = %q`, tt.s, tt.n, s) } } } @@ -136,7 +136,7 @@ func TestSplit(t *testing.T) { } s := Join(a, tt.sep); if s != tt.s { - t.Errorf("Join(Split(%q, %q, %d), %q) = %q", tt.s, tt.sep, tt.n, tt.sep, s); + t.Errorf("Join(Split(%q, %q, %d), %q) = %q", tt.s, tt.sep, tt.n, tt.sep, s) } } } @@ -166,7 +166,7 @@ func TestSplitAfter(t *testing.T) { } s := Join(a, ""); if s != tt.s { - t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s); + t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s) } } } @@ -182,7 +182,7 @@ func runStringTests(t *testing.T, f func(string) string, funcName string, testCa 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); + t.Errorf("%s(%q) = %q; want %q", funcName, tc.in, actual, tc.out) } } } @@ -221,7 +221,7 @@ var trimSpaceTests = []StringTest{ func tenRunes(rune int) string { r := make([]int, 10); for i := range r { - r[i] = rune; + r[i] = rune } return string(r); } @@ -234,14 +234,14 @@ func TestMap(t *testing.T) { m := Map(maxRune, a); expect := tenRunes(unicode.MaxRune); if m != expect { - t.Errorf("growing: expected %q got %q", expect, m); + t.Errorf("growing: expected %q got %q", expect, m) } // 2. Shrink minRune := func(rune int) int { return 'a' }; m = Map(minRune, tenRunes(unicode.MaxRune)); expect = a; if m != expect { - t.Errorf("shrinking: expected %q got %q", expect, m); + t.Errorf("shrinking: expected %q got %q", expect, m) } } @@ -253,18 +253,18 @@ func TestTrimSpace(t *testing.T) { runStringTests(t, TrimSpace, "TrimSpace", tri func equal(m string, s1, s2 string, t *testing.T) bool { if s1 == s2 { - return true; + return true } e1 := Split(s1, "", 0); e2 := Split(s2, "", 0); for i, c1 := range e1 { if i > len(e2) { - break; + break } 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); + t.Errorf("%s diff at %d: U+%04X U+%04X", m, i, r1, r2) } } return false; @@ -274,7 +274,7 @@ func TestCaseConsistency(t *testing.T) { // Make a string of all the runes. a := make([]int, unicode.MaxRune + 1); for i := range a { - a[i] = i; + a[i] = i } s := string(a); // convert the cases. @@ -283,16 +283,16 @@ func TestCaseConsistency(t *testing.T) { // Consistency checks if n := utf8.RuneCountInString(upper); n != unicode.MaxRune + 1 { - t.Error("rune count wrong in upper:", n); + t.Error("rune count wrong in upper:", n) } if n := utf8.RuneCountInString(lower); n != unicode.MaxRune + 1 { - t.Error("rune count wrong in lower:", n); + t.Error("rune count wrong in lower:", n) } if !equal("ToUpper(upper)", ToUpper(upper), upper, t) { - t.Error("ToUpper(upper) consistency fail"); + t.Error("ToUpper(upper) consistency fail") } if !equal("ToLower(lower)", ToLower(lower), lower, t) { - t.Error("ToLower(lower) consistency fail"); + t.Error("ToLower(lower) consistency fail") } /* These fail because of non-one-to-oneness of the data, such as multiple |
