github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/parse/read/any.go (about)

     1  package read
     2  
     3  import "github.com/v2pro/plz/parse"
     4  
     5  func AnyExcept1(src *parse.Source, space []byte, b1 byte) []byte {
     6  	for src.Error() == nil {
     7  		buf := src.Peek()
     8  		for i := 0; i < len(buf); i++ {
     9  			b := buf[i]
    10  			if b == b1 {
    11  				src.ConsumeN(i)
    12  				return space
    13  			}
    14  			space = append(space, b)
    15  		}
    16  		src.Consume()
    17  	}
    18  	return space
    19  }
    20  
    21  func AnyExcept2(src *parse.Source, space []byte, b1 byte, b2 byte) []byte {
    22  	for src.Error() == nil {
    23  		buf := src.Peek()
    24  		for i := 0; i < len(buf); i++ {
    25  			b := buf[i]
    26  			if b == b1 || b == b2 {
    27  				src.ConsumeN(i)
    28  				return space
    29  			}
    30  			space = append(space, b)
    31  		}
    32  		src.Consume()
    33  	}
    34  	return space
    35  }