moved a subset of source file to the kern package
This commit is contained in:
+18
-14
@@ -7,10 +7,13 @@ package expr
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"slices"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
)
|
||||
|
||||
type ListIterator struct {
|
||||
a *ListType
|
||||
a *kern.ListType
|
||||
count int
|
||||
index int
|
||||
start int
|
||||
@@ -18,7 +21,7 @@ type ListIterator struct {
|
||||
step int
|
||||
}
|
||||
|
||||
func NewListIterator(list *ListType, args []any) (it *ListIterator) {
|
||||
func NewListIterator(list *kern.ListType, args []any) (it *ListIterator) {
|
||||
var argc int = 0
|
||||
listLen := len(([]any)(*list))
|
||||
if args != nil {
|
||||
@@ -26,21 +29,21 @@ func NewListIterator(list *ListType, args []any) (it *ListIterator) {
|
||||
}
|
||||
it = &ListIterator{a: list, count: 0, index: -1, start: 0, stop: listLen - 1, step: 1}
|
||||
if argc >= 1 {
|
||||
if i, err := ToGoInt(args[0], "start index"); err == nil {
|
||||
if i, err := kern.ToGoInt(args[0], "start index"); err == nil {
|
||||
if i < 0 {
|
||||
i = listLen + i
|
||||
}
|
||||
it.start = i
|
||||
}
|
||||
if argc >= 2 {
|
||||
if i, err := ToGoInt(args[1], "stop index"); err == nil {
|
||||
if i, err := kern.ToGoInt(args[1], "stop index"); err == nil {
|
||||
if i < 0 {
|
||||
i = listLen + i
|
||||
}
|
||||
it.stop = i
|
||||
}
|
||||
if argc >= 3 {
|
||||
if i, err := ToGoInt(args[2], "step"); err == nil {
|
||||
if i, err := kern.ToGoInt(args[2], "step"); err == nil {
|
||||
if i < 0 {
|
||||
i = -i
|
||||
}
|
||||
@@ -58,7 +61,7 @@ func NewListIterator(list *ListType, args []any) (it *ListIterator) {
|
||||
}
|
||||
|
||||
func NewArrayIterator(array []any) (it *ListIterator) {
|
||||
it = &ListIterator{a: (*ListType)(&array), count: 0, index: -1, start: 0, stop: len(array) - 1, step: 1}
|
||||
it = &ListIterator{a: (*kern.ListType)(&array), count: 0, index: -1, start: 0, stop: len(array) - 1, step: 1}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,26 +78,27 @@ func (it *ListIterator) TypeName() string {
|
||||
}
|
||||
|
||||
func (it *ListIterator) HasOperation(name string) bool {
|
||||
yes := name == NextName || name == ResetName || name == IndexName || name == CountName || name == CurrentName
|
||||
//yes := name == expr.NextName || name == expr.ResetName || name == expr.IndexName || name == expr.CountName || name == expr.CurrentName
|
||||
yes := slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName}, name)
|
||||
return yes
|
||||
}
|
||||
|
||||
func (it *ListIterator) CallOperation(name string, args map[string]any) (v any, err error) {
|
||||
switch name {
|
||||
case NextName:
|
||||
case kern.NextName:
|
||||
v, err = it.Next()
|
||||
case ResetName:
|
||||
case kern.ResetName:
|
||||
err = it.Reset()
|
||||
case CleanName:
|
||||
case kern.CleanName:
|
||||
err = it.Clean()
|
||||
case IndexName:
|
||||
case kern.IndexName:
|
||||
v = int64(it.Index())
|
||||
case CurrentName:
|
||||
case kern.CurrentName:
|
||||
v, err = it.Current()
|
||||
case CountName:
|
||||
case kern.CountName:
|
||||
v = it.count
|
||||
default:
|
||||
err = errNoOperation(name)
|
||||
err = kern.ErrNoOperation(name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user