Removed StringCursor because strings.Reader is a ReaderAt
This commit is contained in:
parent
cfeaaa27e3
commit
a2e9d2cc8d
@ -89,37 +89,3 @@ 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.
|
||||
type StringCursor struct {
|
||||
source string
|
||||
offset uint64
|
||||
}
|
||||
|
||||
func NewString(s string) StringCursor {
|
||||
return StringCursor{source: s}
|
||||
}
|
||||
|
||||
func (sc StringCursor) Read(dst []byte) (n uint64, next Cursor[byte], err error) {
|
||||
if sc.offset == uint64(len(sc.source)) {
|
||||
return 0, sc, io.EOF
|
||||
}
|
||||
copied := copy(dst, sc.source[sc.offset:])
|
||||
if copied < len(dst) {
|
||||
err = io.EOF
|
||||
}
|
||||
n = uint64(copied)
|
||||
sc.offset += n
|
||||
return n, sc, err
|
||||
}
|
||||
|
||||
func (sc StringCursor) Pos() uint64 {
|
||||
return sc.offset
|
||||
}
|
||||
|
||||
func (sc StringCursor) At(pos uint64) Cursor[byte] {
|
||||
sc.offset = pos
|
||||
return sc
|
||||
}
|
||||
|
@ -80,12 +80,6 @@ func TestSliceCursor(t *testing.T) {
|
||||
testCursor(t, cursor.NewSlice[byte])
|
||||
}
|
||||
|
||||
func TestStringCursor(t *testing.T) {
|
||||
testCursor(t, func(b []byte) cursor.StringCursor {
|
||||
return cursor.NewString(string(b))
|
||||
})
|
||||
}
|
||||
|
||||
func TestReaderAtCursor(t *testing.T) {
|
||||
testCursor(t, func(b []byte) cursor.ReaderAtCursor {
|
||||
return cursor.NewReaderAt(bytes.NewReader(b))
|
||||
|
Loading…
Reference in New Issue
Block a user