Esempio n. 1
0
File: edit.go Progetto: chai2010/T
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
}
Esempio n. 2
0
File: editor.go Progetto: chai2010/T
// 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
}
Esempio n. 3
0
File: log.go Progetto: chai2010/T
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)
}