From 1b09d430678d4a6f73b2443463d11f75851aba8a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 16 Oct 2020 00:49:02 -0400 Subject: all: update references to symbols moved from io/ioutil to io The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Emmanuel Odeke --- src/strings/reader_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/strings') 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) } } -- cgit v1.3 From 01efc9a3c54f1b8fc772084e3311b6e1ccdfabec Mon Sep 17 00:00:00 2001 From: "Norman B. Lancaster" Date: Thu, 1 Oct 2020 19:14:04 +0000 Subject: strings: complete documentation of strings.Reader There is no documentation on a number of methods of the strings.Reader struct, so this change adds documentation referring to the relevant io.* interfaces implemented. This is consistent with pre-existing documentation in this struct. Fixes #40381 Change-Id: I3dec65ecafca5b79d85d30a676d297e5ee9ab47e GitHub-Last-Rev: f42429946a2b90b9fbfbd1ea5943f0c50e0439b5 GitHub-Pull-Request: golang/go#40654 Reviewed-on: https://go-review.googlesource.com/c/go/+/247523 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Robert Griesemer Trust: Ian Lance Taylor --- src/strings/reader.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/strings') diff --git a/src/strings/reader.go b/src/strings/reader.go index eb2fa1164c..e03f3c5cf8 100644 --- a/src/strings/reader.go +++ b/src/strings/reader.go @@ -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") -- cgit v1.3 From faa44268116df045813e36c9b57d7309b74f14f6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 29 Oct 2020 17:09:16 -0700 Subject: strings: complete Reader doc string Follow-up on https://golang.org/cl/247523. Change-Id: I9e91a6d77271e640d84851f2e2a4c6d2150a2b43 Reviewed-on: https://go-review.googlesource.com/c/go/+/266438 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- src/strings/reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/strings') diff --git a/src/strings/reader.go b/src/strings/reader.go index e03f3c5cf8..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 { -- cgit v1.3