File: iterator.go

package info (click to toggle)
golang-github-mitch000001-go-hbci 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,468 kB
  • sloc: java: 1,092; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 640 bytes parent folder | download
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
package internal

func NewIterator(data [][]byte) Iterator {
	return &arrayIterator{data: data}
}

type Iterator interface {
	Next() []byte
	NextString() string
	HasNext() bool
	Remainder() [][]byte
}

type arrayIterator struct {
	data     [][]byte
	position int
}

func (a *arrayIterator) Next() []byte {
	if !a.HasNext() {
		return nil
	}
	val := a.data[a.position]
	a.position = a.position + 1
	return val
}

func (a *arrayIterator) NextString() string {
	return string(a.Next())
}

func (a *arrayIterator) HasNext() bool {
	return a.position < len(a.data)
}

func (a *arrayIterator) Remainder() [][]byte {
	return a.data[a.position:]
}