~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/pkg/strings/reader.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        "unicode/utf8"
11
11
)
12
12
 
13
 
// A Reader implements the io.Reader, io.ReaderAt, io.Seeker,
 
13
// A Reader implements the io.Reader, io.ReaderAt, io.Seeker, io.WriterTo,
14
14
// io.ByteScanner, and io.RuneScanner interfaces by reading
15
15
// from a string.
16
16
type Reader struct {
120
120
        return abs, nil
121
121
}
122
122
 
 
123
// WriteTo implements the io.WriterTo interface.
 
124
func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
 
125
        r.prevRune = -1
 
126
        if r.i >= len(r.s) {
 
127
                return 0, nil
 
128
        }
 
129
        s := r.s[r.i:]
 
130
        m, err := io.WriteString(w, s)
 
131
        if m > len(s) {
 
132
                panic("strings.Reader.WriteTo: invalid WriteString count")
 
133
        }
 
134
        r.i += m
 
135
        n = int64(m)
 
136
        if m != len(s) && err == nil {
 
137
                err = io.ErrShortWrite
 
138
        }
 
139
        return
 
140
}
 
141
 
123
142
// NewReader returns a new Reader reading from s.
124
143
// It is similar to bytes.NewBufferString but more efficient and read-only.
125
144
func NewReader(s string) *Reader { return &Reader{s, 0, -1} }