mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
fix comment on strings.LastIndex.
add bytes.LastIndex. add strings.Reader. R=r DELTA=59 (56 added, 0 deleted, 3 changed) OCL=35585 CL=35601
This commit is contained in:
parent
d0aac0ace1
commit
10c7d19e07
5 changed files with 59 additions and 3 deletions
|
|
@ -112,6 +112,21 @@ func Index(s, sep []byte) int {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
|
||||
func LastIndex(s, sep []byte) int {
|
||||
n := len(sep);
|
||||
if n == 0 {
|
||||
return len(s);
|
||||
}
|
||||
c := sep[0];
|
||||
for i := len(s)-n; i >= 0; i-- {
|
||||
if s[i] == c && (n == 1 || Equal(s[i : i+n], sep)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Split splits the array s around each instance of sep, returning an array of subarrays of s.
|
||||
// If sep is empty, Split splits s after each UTF-8 sequence.
|
||||
// If n > 0, split Splits s into at most n subarrays; the last subarray will contain an unsplit remainder.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue