github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/lightning/mydump/bytes.go (about)

     1  // Copyright 2009 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  // Package bytes implements functions for the manipulation of byte slices.
     6  // It is analogous to the facilities of the strings package.
     7  
     8  // this is copy from `bytes/bytes.go`
     9  
    10  package mydump
    11  
    12  // byteSet is a 32-byte value, where each bit represents the presence of a
    13  // given byte value in the set.
    14  type byteSet [8]uint32
    15  
    16  // makeByteSet creates a set of byte value.
    17  func makeByteSet(chars []byte) (as byteSet) {
    18  	for i := 0; i < len(chars); i++ {
    19  		c := chars[i]
    20  		as[c>>5] |= 1 << uint(c&31)
    21  	}
    22  	return as
    23  }
    24  
    25  // contains reports whether c is inside the set.
    26  func (as *byteSet) contains(c byte) bool {
    27  	return (as[c>>5] & (1 << uint(c&31))) != 0
    28  }
    29  
    30  // IndexAnyByte returns the byte index of the first occurrence in s of any of the byte
    31  // points in chars. It returns -1 if  there is no code point in common.
    32  func IndexAnyByte(s []byte, as *byteSet) int {
    33  	for i, c := range s {
    34  		if as.contains(c) {
    35  			return i
    36  		}
    37  	}
    38  	return -1
    39  }