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)
| 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. |
| 782 | func (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. |
no test coverage detected