| 1 |
//go:build !arm64 && !amd64 |
| 2 |
|
| 3 |
package algo |
| 4 |
|
| 5 |
import "bytes" |
| 6 |
|
| 7 |
// indexByteTwo returns the index of the first occurrence of b1 or b2 in s, |
| 8 |
// or -1 if neither is present. |
| 9 |
func IndexByteTwo(s []byte, b1, b2 byte) int { |
| 10 |
i1 := bytes.IndexByte(s, b1) |
| 11 |
if i1 == 0 { |
| 12 |
return 0 |
| 13 |
} |
| 14 |
scope := s |
| 15 |
if i1 > 0 { |
| 16 |
scope = s[:i1] |
| 17 |
} |
| 18 |
if i2 := bytes.IndexByte(scope, b2); i2 >= 0 { |
| 19 |
return i2 |
| 20 |
} |
| 21 |
return i1 |
| 22 |
} |
| 23 |
|
| 24 |
// lastIndexByteTwo returns the index of the last occurrence of b1 or b2 in s, |
| 25 |
// or -1 if neither is present. |
| 26 |
func lastIndexByteTwo(s []byte, b1, b2 byte) int { |
| 27 |
for i := len(s) - 1; i >= 0; i-- { |
| 28 |
if s[i] == b1 || s[i] == b2 { |
| 29 |
return i |
| 30 |
} |
| 31 |
} |
| 32 |
return -1 |
| 33 |
} |