Debian Codegraph @

internal/bytealg/indexbyte_generic.go

raw
1 // Copyright 2023 Charlie Vieth. All rights reserved.
2 // Use of this source code is governed by the MIT license.
3
4 //go:build !s390x && !wasm && !ppc64 && !amd64 && !arm64
5 // +build !s390x,!wasm,!ppc64,!amd64,!arm64
6
7 // Simple implementations for arch's where the standard library does not
8 // appear to use SIMD for IndexByte.
9 //
10 // NOTE(cev): See the comment in indexbyte_simd.go for how the list of GOARCH
11 // build tags was created.
12
13 package bytealg
14
15 import (
16 "bytes"
17 "strings"
18 )
19
20 func isAlpha(c byte) bool {
21 return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
22 }
23
24 func IndexByte(s []byte, c byte) int {
25 if !isAlpha(c) {
26 return bytes.IndexByte(s, c)
27 }
28 c |= ' '
29 for i, cc := range s {
30 if cc|' ' == c {
31 return i
32 }
33 }
34 return -1
35 }
36
37 func IndexByteString(s string, c byte) int {
38 if !isAlpha(c) {
39 return strings.IndexByte(s, c)
40 }
41 c |= ' '
42 for i := 0; i < len(s); i++ {
43 if s[i]|' ' == c {
44 return i
45 }
46 }
47 return -1
48 }