forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
range_iterator.go
49 lines (39 loc) · 1.22 KB
/
range_iterator.go
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
44
45
46
47
48
49
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package xlsx
//RangeIterator is a interface for iterating cells inside of range
type RangeIterator interface {
//Next returns next Cell in range and corresponding indexes
Next() (cIdx int, rIdx int, cell *Cell)
//HasNext returns true if there are cells to iterate or false in other case
HasNext() bool
}
//rangeIterator is object that holds required information for range's iterator
type rangeIterator struct {
r *Range
cIdx int
rIdx int
}
var _ RangeIterator = (*rangeIterator)(nil)
func newRangeIterator(r *Range) RangeIterator {
return &rangeIterator{
r: r,
cIdx: r.bounds.FromCol,
rIdx: r.bounds.FromRow,
}
}
//Next returns next Cell in range and corresponding indexes
func (i *rangeIterator) Next() (cIdx int, rIdx int, cell *Cell) {
cIdx, rIdx, cell = i.cIdx, i.rIdx, i.r.sheet.Cell(i.cIdx, i.rIdx)
i.cIdx++
if i.cIdx > i.r.bounds.ToCol {
i.cIdx = i.r.bounds.FromCol
i.rIdx++
}
return
}
//HasNext returns true if there are cells to iterate or false in other case
func (i *rangeIterator) HasNext() bool {
return i.rIdx <= i.r.bounds.ToRow
}