bytes: port IndexFunc and LastIndexFunc from strings package

This CL basically applies the same changes as

	http://code.google.com/p/go/source/detail?r=5e0a29014e8e

but for bytes package.

R=r, rog
CC=golang-dev
https://golang.org/cl/1670052
This commit is contained in:
Fazlul Shahriar 2010-07-23 12:34:35 -07:00 committed by Rob Pike
parent 2b3508425e
commit e356f1d88f
4 changed files with 180 additions and 80 deletions

View file

@ -422,8 +422,7 @@ func LastIndexFunc(s string, f func(r int) bool) int {
// indexFunc is the same as IndexFunc except that if
// truth==false, the sense of the predicate function is
// inverted. We could use IndexFunc directly, but this
// way saves a closure allocation.
// inverted.
func indexFunc(s string, f func(r int) bool, truth bool) int {
start := 0
for start < len(s) {
@ -442,8 +441,7 @@ func indexFunc(s string, f func(r int) bool, truth bool) int {
// lastIndexFunc is the same as LastIndexFunc except that if
// truth==false, the sense of the predicate function is
// inverted. We could use IndexFunc directly, but this
// way saves a closure allocation.
// inverted.
func lastIndexFunc(s string, f func(r int) bool, truth bool) int {
end := len(s)
for end > 0 {