| 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 && !ppc64 && !amd64 && !arm64 |
| 5 |
// +build !s390x,!ppc64,!amd64,!arm64 |
| 6 |
|
| 7 |
// NOTE(cev): See the comment in indexbyte_simd.go for how the list of GOARCH |
| 8 |
// build tags was created (note: wasm is included here because it lacks an |
| 9 |
// assembly implementation of Count). |
| 10 |
|
| 11 |
package bytealg |
| 12 |
|
| 13 |
func Count(b []byte, c byte) int { |
| 14 |
if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' { |
| 15 |
n := 0 |
| 16 |
c |= ' ' |
| 17 |
for _, cc := range b { |
| 18 |
if cc|' ' == c { |
| 19 |
n++ |
| 20 |
} |
| 21 |
} |
| 22 |
return n |
| 23 |
} |
| 24 |
n := 0 |
| 25 |
for _, x := range b { |
| 26 |
if x == c { |
| 27 |
n++ |
| 28 |
} |
| 29 |
} |
| 30 |
return n |
| 31 |
} |
| 32 |
|
| 33 |
func CountString(s string, c byte) int { |
| 34 |
if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' { |
| 35 |
n := 0 |
| 36 |
c |= ' ' |
| 37 |
for i := 0; i < len(s); i++ { |
| 38 |
if s[i]|' ' == c { |
| 39 |
n++ |
| 40 |
} |
| 41 |
} |
| 42 |
return n |
| 43 |
} |
| 44 |
n := 0 |
| 45 |
for i := 0; i < len(s); i++ { |
| 46 |
if s[i] == c { |
| 47 |
n++ |
| 48 |
} |
| 49 |
} |
| 50 |
return n |
| 51 |
} |