MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / mustReadWhileFn

Method mustReadWhileFn

xmlparser/decoder.go:782–812  ·  view source on GitHub ↗

mustReadWhileFn reads bytes to the buffer while the provided function returns true. The byte that causes the function to return false is not included in the buffer.

(f func(byte) bool)

Source from the content-addressed store, hash-verified

780// mustReadWhileFn reads bytes to the buffer while the provided function returns true.
781// The byte that causes the function to return false is not included in the buffer.
782func (d *Decoder) mustReadWhileFn(f func(byte) bool) bool {
783 for {
784 b, ok := d.mustPeekBuffered()
785 if !ok {
786 return false
787 }
788
789 found := false
790 for i, c := range b {
791 if !f(c) {
792 // Found a byte that does not satisfy the condition.
793 // Trim the bytes up to (but not including) this byte.
794 b = b[:i]
795 found = true
796 break
797 }
798 }
799
800 d.buf.Write(b)
801
802 // Discard the bytes we've read.
803 if !d.discard(len(b)) {
804 return false
805 }
806
807 if found {
808 // We've read up to the delimiter byte, break the loop.
809 return true
810 }
811 }
812}
813
814// peek peeks at the next n bytes without advancing the reader.
815// If an error occurs, it sets d.err and returns false.

Callers 2

readAttrValueMethod · 0.95
readNameMethod · 0.95

Calls 3

mustPeekBufferedMethod · 0.95
discardMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected