diff options
| author | Katie Hockman <katie@golang.org> | 2020-12-14 10:03:05 -0500 |
|---|---|---|
| committer | Katie Hockman <katie@golang.org> | 2020-12-14 10:06:13 -0500 |
| commit | 0345ede87ee12698988973884cfc0fd3d499dffd (patch) | |
| tree | 7123cff141ee5661208d2f5f437b8f5252ac7f6a /src/strings | |
| parent | 4651d6b267818b0e0d128a5443289717c4bb8cbc (diff) | |
| parent | 0a02371b0576964e81c3b40d328db9a3ef3b031b (diff) | |
| download | go-0345ede87ee12698988973884cfc0fd3d499dffd.tar.xz | |
[dev.fuzz] all: merge master into dev.fuzz
Change-Id: I5d8c8329ccc9d747bd81ade6b1cb7cb8ae2e94b2
Diffstat (limited to 'src/strings')
| -rw-r--r-- | src/strings/reader.go | 10 | ||||
| -rw-r--r-- | src/strings/reader_test.go | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/strings/reader.go b/src/strings/reader.go index eb2fa1164c..6f069a62ca 100644 --- a/src/strings/reader.go +++ b/src/strings/reader.go @@ -10,8 +10,8 @@ import ( "unicode/utf8" ) -// A Reader implements the io.Reader, io.ReaderAt, io.Seeker, io.WriterTo, -// io.ByteScanner, and io.RuneScanner interfaces by reading +// A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, +// io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading // from a string. // The zero value for Reader operates like a Reader of an empty string. type Reader struct { @@ -35,6 +35,7 @@ func (r *Reader) Len() int { // to any other method. func (r *Reader) Size() int64 { return int64(len(r.s)) } +// Read implements the io.Reader interface. func (r *Reader) Read(b []byte) (n int, err error) { if r.i >= int64(len(r.s)) { return 0, io.EOF @@ -45,6 +46,7 @@ func (r *Reader) Read(b []byte) (n int, err error) { return } +// ReadAt implements the io.ReaderAt interface. func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) { // cannot modify state - see io.ReaderAt if off < 0 { @@ -60,6 +62,7 @@ func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) { return } +// ReadByte implements the io.ByteReader interface. func (r *Reader) ReadByte() (byte, error) { r.prevRune = -1 if r.i >= int64(len(r.s)) { @@ -70,6 +73,7 @@ func (r *Reader) ReadByte() (byte, error) { return b, nil } +// UnreadByte implements the io.ByteScanner interface. func (r *Reader) UnreadByte() error { if r.i <= 0 { return errors.New("strings.Reader.UnreadByte: at beginning of string") @@ -79,6 +83,7 @@ func (r *Reader) UnreadByte() error { return nil } +// ReadRune implements the io.RuneReader interface. func (r *Reader) ReadRune() (ch rune, size int, err error) { if r.i >= int64(len(r.s)) { r.prevRune = -1 @@ -94,6 +99,7 @@ func (r *Reader) ReadRune() (ch rune, size int, err error) { return } +// UnreadRune implements the io.RuneScanner interface. func (r *Reader) UnreadRune() error { if r.i <= 0 { return errors.New("strings.Reader.UnreadRune: at beginning of string") diff --git a/src/strings/reader_test.go b/src/strings/reader_test.go index a4c211d699..5adea6f7ab 100644 --- a/src/strings/reader_test.go +++ b/src/strings/reader_test.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "strings" "sync" "testing" @@ -162,7 +161,7 @@ func TestWriteTo(t *testing.T) { // tests that Len is affected by reads, but Size is not. func TestReaderLenSize(t *testing.T) { r := strings.NewReader("abc") - io.CopyN(ioutil.Discard, r, 1) + io.CopyN(io.Discard, r, 1) if r.Len() != 2 { t.Errorf("Len = %d; want 2", r.Len()) } @@ -182,7 +181,7 @@ func TestReaderReset(t *testing.T) { if err := r.UnreadRune(); err == nil { t.Errorf("UnreadRune: expected error, got nil") } - buf, err := ioutil.ReadAll(r) + buf, err := io.ReadAll(r) if err != nil { t.Errorf("ReadAll: unexpected error: %v", err) } @@ -228,7 +227,7 @@ func TestReaderZero(t *testing.T) { t.Errorf("UnreadRune: got nil, want error") } - if n, err := (&strings.Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil { + if n, err := (&strings.Reader{}).WriteTo(io.Discard); n != 0 || err != nil { t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err) } } |
