1
0
Fork 0

Simpla data buffer

This commit is contained in:
Gregory Eremin 2015-02-18 20:26:13 +07:00
parent b458480c68
commit 9b787b749b
1 changed files with 34 additions and 0 deletions

34
buffer/data.go Normal file
View File

@ -0,0 +1,34 @@
package buffer
import (
"bytes"
"unicode/utf8"
)
type (
DataBuffer struct {
input []byte
size uint64
pos uint64
}
)
func NewDataBuffer(input []byte) *DataBuffer {
return &DataBuffer{
input: input,
size: uint64(len(input)),
}
}
func (b *DataBuffer) Next() rune {
var buf bytes.Buffer
for b.pos < b.size-1 {
buf.WriteByte(b.input[b.pos])
b.pos++
if ok := utf8.FullRune(buf.Bytes()); ok {
r, _ := utf8.DecodeRune(buf.Bytes())
return r
}
}
return 0
}