dict-iterator.go: fixed behaviour of NewDictIterator() with no args

This commit is contained in:
Celestino Amoroso 2026-04-23 22:06:23 +02:00
parent 9e4252173b
commit c39ee7cec0

View File

@ -68,9 +68,15 @@ func (it *DictIterator) makeKeys(m map[any]any, sort sortType) {
func NewDictIterator(dict *DictType, args []any) (it *DictIterator, err error) {
var sortType = sortTypeNone
var s string
var argAny any
it = &DictIterator{a: dict, count: 0, index: -1, keys: nil, iterMode: dictIterModeKeys}
if len(args) > 0 {
if s, err = ToGoString(args[0], "sort type"); err == nil {
argAny = args[0]
} else {
argAny = "default"
}
if s, err = ToGoString(argAny, "sort type"); err == nil {
switch strings.ToLower(s) {
case "a", "asc":
sortType = sortTypeAsc
@ -84,8 +90,14 @@ func NewDictIterator(dict *DictType, args []any) (it *DictIterator, err error) {
err = fmt.Errorf("invalid sort type %q", s)
}
if err == nil && len(args) > 1 {
if s, err = ToGoString(args[1], "iteration mode"); err == nil {
if err == nil {
if len(args) > 1 {
argAny = args[1]
} else {
argAny = "default"
}
if s, err = ToGoString(argAny, "iteration mode"); err == nil {
switch strings.ToLower(s) {
case "k", "key", "keys":
it.iterMode = dictIterModeKeys
@ -101,7 +113,7 @@ func NewDictIterator(dict *DictType, args []any) (it *DictIterator, err error) {
}
}
}
}
it.makeKeys(*dict, sortType)
return
}