示例#1
0
文件: edit.go 项目: 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
}
示例#2
0
文件: editor.go 项目: 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
}
示例#3
0
文件: log.go 项目: 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)
}