2024-09-02 17:04:00 +00:00
|
|
|
package cursor
|
|
|
|
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
// BufferedReaderAt uses a buffer to supplement an io.Reader
|
|
|
|
// with limited backward seeking.
|
|
|
|
type BufferedReaderAt struct{}
|
|
|
|
|
2024-09-03 19:55:32 +00:00
|
|
|
func NewBufferedReaderAt(r io.Reader, minBuffer uint64) *BufferedReaderAt {
|
|
|
|
return nil
|
|
|
|
}
|
2024-09-02 17:04:00 +00:00
|
|
|
|
|
|
|
// ReadAt reads bytes from the underlying reader. If the offset is after
|
|
|
|
// the end of the buffer, ReadAt will first read and ignore bytes from the
|
|
|
|
// underlying reader until it reaches the offset. If the offset is
|
|
|
|
// before the start of the buffer, ReadAt will return an error.
|
|
|
|
//
|
|
|
|
// If your parser needs unlimited lookahead, you should probably
|
|
|
|
// just read the whole input into a slice and use BytesCursor.
|
2024-09-03 19:55:32 +00:00
|
|
|
func (b *BufferedReaderAt) ReadAt(dst []byte, offset int64) (int, error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
2024-09-02 17:04:00 +00:00
|
|
|
|
|
|
|
// RuneReader is an io.RuneReader backed by a Cursor, for compatibility
|
|
|
|
// with the regexp package.
|
|
|
|
type RuneReader struct {
|
|
|
|
cursor Cursor[byte]
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRuneReader(c Cursor[byte]) *RuneReader {
|
|
|
|
return &RuneReader{cursor: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RuneReader) Read(dst []byte) (int, error) {
|
|
|
|
n, c, err := r.cursor.Read(dst)
|
|
|
|
r.cursor = c
|
|
|
|
return int(n), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RuneReader) Cursor() Cursor[byte] {
|
|
|
|
return r.cursor
|
|
|
|
}
|