github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/bytealg/count_generic.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !amd64 && !arm && !arm64 && !ppc64le && !ppc64 && !riscv64 && !s390x
     6  
     7  package bytealg
     8  
     9  func Count(b []byte, c byte) int {
    10  	n := 0
    11  	for _, x := range b {
    12  		if x == c {
    13  			n++
    14  		}
    15  	}
    16  	return n
    17  }
    18  
    19  func CountString(s string, c byte) int {
    20  	n := 0
    21  	for i := 0; i < len(s); i++ {
    22  		if s[i] == c {
    23  			n++
    24  		}
    25  	}
    26  	return n
    27  }