-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.go
More file actions
43 lines (36 loc) · 719 Bytes
/
buffer.go
File metadata and controls
43 lines (36 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import "bytes"
// Buffer with undo and save
type Buffer struct {
*bytes.Buffer
length int
}
// NewBufferFromString new buffer from given string
func NewBufferFromString(str string) *Buffer {
b := &Buffer{
bytes.NewBufferString(str),
0,
}
return b
}
// Len returns saved length
func (b *Buffer) Len() int {
return b.length
}
// Undo trancate last operation
// delete unsaved bytes which is writen since last
// Save()
func (b *Buffer) Undo() {
b.Truncate(b.length)
}
// Save all bytes by setting length as buffer length
func (b *Buffer) Save() {
b.length = b.Buffer.Len()
}
/*
func (b *Buffer) String() string {
sl := make([]byte, b.length, b.length)
b.Read(sl)
return string(sl)
}
*/