mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
2b3508425e
commit
e356f1d88f
4 changed files with 180 additions and 80 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue