file iterators refactored
This commit is contained in:
@@ -5,12 +5,51 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/file"
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
)
|
||||
|
||||
const paramHandleOrPath = "handle-or-path"
|
||||
|
||||
type fileIterBase struct {
|
||||
reader *file.Reader
|
||||
index int64
|
||||
count int64
|
||||
autoClose bool
|
||||
}
|
||||
|
||||
func (it *fileIterBase) Count() int64 {
|
||||
return it.count
|
||||
}
|
||||
|
||||
func (it *fileIterBase) Index() int64 {
|
||||
return it.index
|
||||
}
|
||||
|
||||
func (it *fileIterBase) HasOperation(name string) bool {
|
||||
return slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName}, name)
|
||||
}
|
||||
|
||||
func (it *fileIterBase) reset() {
|
||||
it.index = -1
|
||||
it.count = 0
|
||||
}
|
||||
|
||||
func (it *fileIterBase) increment() {
|
||||
it.index++
|
||||
it.count++
|
||||
}
|
||||
|
||||
func (it *fileIterBase) repr(typeName string) string {
|
||||
if it.reader.Valid() {
|
||||
return fmt.Sprintf("$(%s@%q)", fileLineIteratorType, it.reader.GetName())
|
||||
}
|
||||
return fmt.Sprintf("$(%s@<nil>)", fileLineIteratorType)
|
||||
}
|
||||
|
||||
func initFileHandle(ctx kern.ExprContext, name string, args map[string]any) (handle *file.Reader, invalidFileHandle any, autoClose bool, err error) {
|
||||
var ok bool
|
||||
|
||||
|
||||
Reference in New Issue
Block a user