Implemented (but not tested) cursor.RuneReader
This commit is contained in:
@ -25,6 +25,9 @@ type Cursor[Datum any] interface {
|
||||
|
||||
// Pos returns the Cursor's position within the source.
|
||||
Pos() uint64
|
||||
|
||||
// At returns a new cursor at the position pos.
|
||||
At(pos uint64) Cursor[Datum]
|
||||
}
|
||||
|
||||
type SliceCursor[Datum any] struct {
|
||||
@ -56,6 +59,11 @@ func (sc SliceCursor[Datum]) Pos() uint64 {
|
||||
return sc.offset
|
||||
}
|
||||
|
||||
func (sc SliceCursor[Datum]) At(pos uint64) Cursor[Datum] {
|
||||
sc.offset = pos
|
||||
return sc
|
||||
}
|
||||
|
||||
type ReaderAtCursor struct {
|
||||
r io.ReaderAt
|
||||
pos uint64
|
||||
@ -77,6 +85,11 @@ func (rac ReaderAtCursor) Pos() uint64 {
|
||||
return rac.pos
|
||||
}
|
||||
|
||||
func (rac ReaderAtCursor) At(pos uint64) Cursor[byte] {
|
||||
rac.pos = pos
|
||||
return rac
|
||||
}
|
||||
|
||||
// StringCursor is identical to SliceCursor[byte], but uses a string as its data source.
|
||||
// The advantage is that creating a StringCursor does not require copying the source
|
||||
// string into a []byte.
|
||||
@ -105,3 +118,8 @@ func (sc StringCursor) Read(dst []byte) (n uint64, next Cursor[byte], err error)
|
||||
func (sc StringCursor) Pos() uint64 {
|
||||
return sc.offset
|
||||
}
|
||||
|
||||
func (sc StringCursor) At(pos uint64) Cursor[byte] {
|
||||
sc.offset = pos
|
||||
return sc
|
||||
}
|
||||
|
Reference in New Issue
Block a user