github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/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  // +build !amd64,!arm,!arm64,!ppc64le,!ppc64,!riscv64,!s390x
     7  
     8  package bytealg
     9  
    10  func Count(b []byte, c byte) int {
    11  	n := 0
    12  	for _, x := range b {
    13  		if x == c {
    14  			n++
    15  		}
    16  	}
    17  	return n
    18  }
    19  
    20  func CountString(s string, c byte) int {
    21  	n := 0
    22  	for i := 0; i < len(s); i++ {
    23  		if s[i] == c {
    24  			n++
    25  		}
    26  	}
    27  	return n
    28  }