// ReadRune reads and returns the next UTF-8-encoded
// Unicode code point from the buffer.
// If no bytes are available, the error returned is io.EOF.
// If the bytes are an erroneous UTF-8 encoding, it
// consumes one byte and returns U+FFFD, 1.
185652
func (b *Builder) ReadRune() (r rune, size int, err error) {
	b.lastRead = opInvalid
	if b.off >= len(b.buf) {
		// Buffer is empty, reset to recover space.
		b.Truncate(0)
		return 0, 0, io.EOF
	}
	b.lastRead = opReadRune
	c := b.buf[b.off]
	if c < utf8.RuneSelf {
		b.off++
		return rune(c), 1, nil
	}
	r, n := utf8.DecodeRune(b.buf[b.off:])
	b.off += n
	return r, n, nil
}
824689
func (b *Buffer) ReadByte() (c byte, err error) {
	if b.off >= len(b.buf) {
		// Buffer is empty, reset to recover space.
		b.Truncate(0)
		return 0, io.EOF
	}
	c = b.buf[b.off]
	b.off++
	return c, nil
}
361169
func (l *lexer) unread(r ...rune) {
	// ignore EOF runes
	_r := make([]rune, 0)
	for _, _rune := range r {
		if _rune != _EOF {
			_r = append(_r, _rune)
		}
	}

	// initialise the unread rune list if necessary
	if l._unread == nil {
		l._unread = make([]rune, 0)
	}
	if len(_r) != 0 {
		l._unread = append(l._unread, _r...)
	}

	// decrement the offset and column counts
	//      - we have to take care of column being 0
	//      - at present we can only unwind across a single line boundary
	_length := len(_r)
	for ; _length > 0; _length-- {
		l._offset--
		if l._column == 1 {
			_length := len(l._previous)
			if _length > 0 {
				l._column = l._previous[_length-1]
				l._previous = l._previous[:_length-1]
				l._line--
			}
		} else {
			l._column--
		}
	}
}
91076
func Parse(r io.Reader) (Value, error) {
	rr := bufio.NewReader(r)
	data := []rune{}
	for {
		c, _, err := rr.ReadRune()
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, err
		}
		data = append(data, c)
	}
	return parse(data)
}
1191210
func (cr *iso88591CharsetReader) ReadByte() (b byte, err error) {
	if cr.buffer.Len() <= 0 {
		r, err := cr.reader.ReadByte()
		if err != nil {
			return 0, err
		}
		if r < utf8.RuneSelf {
			return r, nil
		}
		cr.buffer.WriteRune(rune(r))
	}
	return cr.buffer.ReadByte()
}
306319
func (rwops *RWops) ReadU8() uint8 {
	if rwops == nil {
		return 0
	}
	return uint8(C.SDL_ReadU8(rwops.cptr()))
}
981551
func (r *ByteReader) ReadByte() (byte, error) {
	if r.off >= len(r.buf) {
		return 0, io.EOF
	}
	return r.readByte(), nil
}
972827
func (br *bufReader) ReadText(encoding Encoding) []byte {
	if br.err != nil {
		return nil
	}

	var text []byte
	delims := encoding.TerminationBytes
	text, br.err = br.readTillDelims(delims)
	br.Discard(len(delims))

	return text
}
1167449
func (buf *Buffer) ReadByte() (byte, error) {
	if len(buf.buf) == 0 {
		return 0, io.EOF
	}

	c := buf.buf[0]
	buf.buf[0] = 0
	buf.buf = buf.buf[1:]
	return c, nil
}
440587
func (ar *AnsiReader) Read(b []byte) (int, error) {
	if len(b) == 0 {
		return 0, nil
	}

	if len(ar.buf) == 0 {
		var runes []rune
		var read uint32
		rec := new(inputRecord)

		for runes == nil {
			ret, _, err := readConsoleInput.Call(ar.fd, uintptr(unsafe.Pointer(rec)),
				1, uintptr(unsafe.Pointer(&read)))
			if ret == 0 {
				return 0, err
			}

			if rec.eventType != keyEventType {
				continue
			}

			ke := (*keyEventRecord)(unsafe.Pointer(&rec.event))
			if ke.keyDown == 0 {
				continue
			}

			shift := false
			if ke.controlKeyState&shiftKey != 0 {
				shift = true
			}

			ctrl := false
			if ke.controlKeyState&leftCtrlKey != 0 || ke.controlKeyState&rightCtrlKey != 0 {
				ctrl = true
			}

			alt := false
			if ke.controlKeyState&leftAltKey != 0 || ke.controlKeyState&rightAltKey != 0 {
				alt = true
			}

			// Backspace, Return, Space.
			if ke.char == ctrlH || ke.char == returnKey || ke.char == spaceKey {
				code := string(returnKey)
				if ke.char == ctrlH {
					code = string(backKey)
				} else if ke.char == spaceKey {
					code = string(spaceKey)
				}

				if alt {
					code = string(escKey) + code
				}

				runes = []rune(code)
				break
			}

			// Generate runes for the chars and key codes.
			if ke.char > 0 {
				runes = []rune{rune(ke.char)}
			} else {
				code := string(escKey)

				switch ke.virtualKeyCode {
				case f1Key:
					if ctrl {
						continue
					}

					code += ar.shortFunction("P", shift, ctrl, alt)
				case f2Key:
					code += ar.shortFunction("Q", shift, ctrl, alt)
				case f3Key:
					code += ar.shortFunction("R", shift, ctrl, alt)
				case f4Key:
					code += ar.shortFunction("S", shift, ctrl, alt)
				case f5Key:
					code += ar.longFunction("15", shift, ctrl, alt)
				case f6Key:
					code += ar.longFunction("17", shift, ctrl, alt)
				case f7Key:
					code += ar.longFunction("18", shift, ctrl, alt)
				case f8Key:
					code += ar.longFunction("19", shift, ctrl, alt)
				case f9Key:
					code += ar.longFunction("20", shift, ctrl, alt)
				case f10Key:
					code += ar.longFunction("21", shift, ctrl, alt)
				case f11Key:
					code += ar.longFunction("23", shift, ctrl, alt)
				case f12Key:
					code += ar.longFunction("24", shift, ctrl, alt)
				case insertKey:
					if shift || ctrl {
						continue
					}

					code += ar.longFunction("2", shift, ctrl, alt)
				case deleteKey:
					code += ar.longFunction("3", shift, ctrl, alt)
				case homeKey:
					code += "OH"
				case endKey:
					code += "OF"
				case pgupKey:
					if shift {
						continue
					}

					code += ar.longFunction("5", shift, ctrl, alt)
				case pgdownKey:
					if shift {
						continue
					}

					code += ar.longFunction("6", shift, ctrl, alt)
				case upKey:
					code += ar.arrow("A", shift, ctrl, alt)
				case downKey:
					code += ar.arrow("B", shift, ctrl, alt)
				case leftKey:
					code += ar.arrow("D", shift, ctrl, alt)
				case rightKey:
					code += ar.arrow("C", shift, ctrl, alt)
				default:
					continue
				}

				runes = []rune(code)
			}
		}

		ar.buf = runes
	}

	// Get items from the buffer.
	var n int
	for i, r := range ar.buf {
		if utf8.RuneLen(r) > len(b) {
			ar.buf = ar.buf[i:]
			return n, nil
		}

		nr := utf8.EncodeRune(b, r)
		b = b[nr:]
		n += nr
	}

	ar.buf = nil
	return n, nil
}
1054044
func ReadByte(r io.Reader) (ret byte, err error) {
	var be [1]byte
	valBytes := be[0:1]

	if _, err = io.ReadFull(r, valBytes); err != nil {
		return 0, err
	}

	return valBytes[0], nil
}
873621
func (u *UTF8Reader) Read(p []byte) (n int, err error) {
	n, err = u.Source.Read(p)

	accepted := 0
	s, c := u.state, u.codep
	for i := 0; i < n; i++ {
		c, s = decode(s, c, p[i])
		if s == utf8Reject {
			u.state = s
			return accepted, ErrInvalidUTF8
		}
		if s == utf8Accept {
			accepted = i + 1
		}
	}
	u.state, u.codep = s, c
	u.accepted = accepted

	return
}
109490
func (b *Buffer) Read8() uint8 {
	v, ok := b.consume(1)
	if !ok {
		return 0
	}
	return uint8(v[0])
}
284226
func (a Afero) ReadFile(filename string) ([]byte, error) {
	return ReadFile(a.Fs, filename)
}
1213943
func runeReader(r io.Reader) io.RuneReader {
	if rr, ok := r.(io.RuneReader); ok {
		return rr
	}
	return bufio.NewReader(r)
}
1172134
func (sc *scanner) peekRune() rune {
	if len(sc.rest) == 0 {
		return 0
	}

	// fast path: ASCII
	if b := sc.rest[0]; b < utf8.RuneSelf {
		if b == '\r' {
			return '\n'
		}
		return rune(b)
	}

	r, _ := utf8.DecodeRune(sc.rest)
	return r
}
166909
func nextRune(index int, input []rune) (newIndex int, r rune, escaped bool, err error) {
	if index >= len(input) {
		newIndex = index
		err = errEndOfInput
		return
	}

	if m, ok := modifierRunes[input[index]]; ok {
		switch m {

		case ModifierBackslash:
			if index < len(input)-1 {
				newIndex, r, escaped = index+2, input[index+1], true
			} else if index == len(input)-1 {
				err = errors.Wrap(ErrInvalidInput, invalidInputMessage(input, index, "input ends with a \\ (escape) character"))
			}
		default:
			panic(errors.Wrapf(errBadImplementation, "encountered unhandled modifier: %v", m))
		}
	} else {
		newIndex, r, escaped = index+1, input[index], false
	}

	return
}