file iterators refactored

This commit is contained in:
2026-05-08 11:01:50 +02:00
parent c10053253c
commit c7dce8288f
3 changed files with 62 additions and 82 deletions
+39
View File
@@ -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