GoDict/internal/dict/dict.go
2024-02-18 06:05:09 +03:30

63 lines
908 B
Go

package dict
type Dict map[string]interface{}
func New() Dict {
return make(Dict)
}
func IsDict(a interface{}) bool {
_, ok := a.(Dict)
return ok
}
func (d Dict) HasKey(key string) bool {
_, ok := d[key]
return ok
}
func Copy(dest *Dict, src Dict) {
if *dest == nil {
*dest = make(Dict)
}
for k, v := range src {
if vv, ok := v.(Dict); ok {
t := make(Dict)
Copy(&t, vv)
(*dest)[k] = t
} else {
(*dest)[k] = v
}
}
}
func (dest *Dict) CopyFrom(src Dict) {
if *dest == nil {
*dest = make(Dict)
}
for k, v := range src {
if vv, ok := v.(Dict); ok {
t := make(Dict)
t.CopyFrom(vv)
(*dest)[k] = t
} else {
(*dest)[k] = v
}
}
}
func (src Dict) CopyTo(dest *Dict) {
if *dest == nil {
*dest = make(Dict)
}
for k, v := range src {
if vv, ok := v.(Dict); ok {
t := make(Dict)
vv.CopyTo(&t)
(*dest)[k] = t
} else {
(*dest)[k] = v
}
}
}