Removed StringCursor because strings.Reader is a ReaderAt

This commit is contained in:
Brandon Dyck 2024-09-03 16:13:21 -06:00
parent cfeaaa27e3
commit a2e9d2cc8d
2 changed files with 0 additions and 40 deletions

View File

@ -89,37 +89,3 @@ func (rac ReaderAtCursor) At(pos uint64) Cursor[byte] {
rac.pos = pos rac.pos = pos
return rac 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
}

View File

@ -80,12 +80,6 @@ func TestSliceCursor(t *testing.T) {
testCursor(t, cursor.NewSlice[byte]) 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) { func TestReaderAtCursor(t *testing.T) {
testCursor(t, func(b []byte) cursor.ReaderAtCursor { testCursor(t, func(b []byte) cursor.ReaderAtCursor {
return cursor.NewReaderAt(bytes.NewReader(b)) return cursor.NewReaderAt(bytes.NewReader(b))