indexbyte2_other.go
This file
Path
src/algo/indexbyte2_other.go
33 lines · 656 bytes · Go
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–33why, one step back1//go:build !arm64 && !amd6423package algo45import "bytes"67// indexByteTwo returns the index of the first occurrence of b1 or b2 in s,8// or -1 if neither is present.9func IndexByteTwo(s []byte, b1, b2 byte) int {10 i1 := bytes.IndexByte(s, b1)11 if i1 == 0 {12 return 013 }14 scope := s15 if i1 > 0 {16 scope = s[:i1]17 }18 if i2 := bytes.IndexByte(scope, b2); i2 >= 0 {19 return i220 }21 return i122}2324// lastIndexByteTwo returns the index of the last occurrence of b1 or b2 in s,25// or -1 if neither is present.26func 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 i30 }31 }32 return -133}