func (e print) do(ed *Editor, w io.Writer) (addr, error) { at, err := e.a.where(ed) if err != nil { return addr{}, err } r := runes.LimitReader(ed.buf.runes.Reader(at.from), at.size()) if _, err := runes.Copy(runes.UTF8Writer(w), r); err != nil { return addr{}, err } return at, nil }
// Change changes the string identified by at // to contain the runes from the Reader. // // This method must be called with the Lock held. func (buf *Buffer) change(at addr, src runes.Reader) error { if err := buf.runes.Delete(at.size(), at.from); err != nil { return err } n, err := runes.Copy(buf.runes.Writer(at.from), src) if err != nil { return err } for _, ed := range buf.eds { for m := range ed.marks { ed.marks[m] = ed.marks[m].update(at, n) } } return nil }
func (l *log) append(seq int32, at addr, src runes.Reader) error { prev := l.last l.last = l.buf.Size() n, err := runes.Copy(l.buf.Writer(l.last), src) if err != nil { return err } // Insert the header before the data. h := header{ prev: prev, at: at, size: n, seq: seq, } return l.buf.Insert(h.marshal(), l.last) }