]> Cypherpunks repositories - gostls13.git/commitdiff
strings: fix minor bug in LastIndexFunc
authorRoger Peppe <rogpeppe@gmail.com>
Wed, 22 Sep 2010 02:58:09 +0000 (22:58 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 22 Sep 2010 02:58:09 +0000 (22:58 -0400)
R=r, rsc
CC=golang-dev
https://golang.org/cl/2250042

src/pkg/strings/strings.go
src/pkg/strings/strings_test.go

index 89da9dc224b0d89a344804ed74e3c8cc5c3bb8b8..e3989c758224af1f60d25efe7b117bd3ff6a671f 100644 (file)
@@ -463,7 +463,7 @@ func lastIndexFunc(s string, f func(r int) bool, truth bool) int {
                                }
                        }
                        if start < 0 {
-                               return -1
+                               start = 0
                        }
                        var wid int
                        rune, wid = utf8.DecodeRuneInString(s[start:end])
index 3206f5e1433311bba3f249bc8b52456312785a66..57bc7a3b3724dd7a8a47d44edaa66d662f4d705c 100644 (file)
@@ -514,6 +514,7 @@ var indexFuncTests = []IndexFuncTest{
        IndexFuncTest{"\xc0☺\xc0\xc0", not(isValidRune), 0, 5},
        IndexFuncTest{"ab\xc0a\xc0cd", not(isValidRune), 2, 4},
        IndexFuncTest{"a\xe0\x80cd", not(isValidRune), 1, 2},
+       IndexFuncTest{"\x80\x80\x80\x80", not(isValidRune), 0, 3},
 }
 
 func TestIndexFunc(t *testing.T) {