github.com/primecitizens/pcz/std@v0.2.1/core/bytealg/notpcz.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build !pcz
     5  
     6  package bytealg
     7  
     8  import (
     9  	"bytes"
    10  	"strings"
    11  )
    12  
    13  func CountSlice(b []byte, c byte) (n int) {
    14  	for _, x := range b {
    15  		if x == c {
    16  			n++
    17  		}
    18  	}
    19  
    20  	return
    21  }
    22  
    23  func IndexSlice(s, sep []byte) int {
    24  	return bytes.Index(s, sep)
    25  }
    26  
    27  func IndexSliceByte(b []byte, c byte) int {
    28  	return bytes.IndexByte(b, c)
    29  }
    30  
    31  func Count(s string, c byte) (n int) {
    32  	for i := 0; i < len(s); i++ {
    33  		if s[i] == c {
    34  			n++
    35  		}
    36  	}
    37  
    38  	return
    39  }
    40  
    41  func Index(s, substr string) int {
    42  	return strings.Index(s, substr)
    43  }
    44  
    45  func IndexByte(s string, c byte) int {
    46  	return strings.IndexByte(s, c)
    47  }