mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-27 22:08:15 +02:00
Feature/#95 deepclone (#101)
* rename method Clone to Copy * added Cloneable interface * added Value to Cloneable interface * implemented Cloneable intefrace by array * implemented Cloneable interface by Object * unit tests for Object.Clone * move core.IsCloneable to value.go * change Clone function * move IsClonable to package values
This commit is contained in:
@@ -141,7 +141,7 @@ func (t *Object) Hash() uint64 {
|
||||
return h.Sum64()
|
||||
}
|
||||
|
||||
func (t *Object) Clone() core.Value {
|
||||
func (t *Object) Copy() core.Value {
|
||||
c := NewObject()
|
||||
|
||||
for k, v := range t.value {
|
||||
@@ -202,3 +202,20 @@ func (t *Object) Remove(key String) {
|
||||
func (t *Object) SetIn(path []core.Value, value core.Value) error {
|
||||
return SetIn(t, path, value)
|
||||
}
|
||||
|
||||
func (t *Object) Clone() core.Cloneable {
|
||||
cloned := NewObject()
|
||||
|
||||
var value core.Value
|
||||
var keyString String
|
||||
for key := range t.value {
|
||||
keyString = NewString(key)
|
||||
value, _ = t.Get(keyString)
|
||||
if IsCloneable(value) {
|
||||
value = value.(core.Cloneable).Clone()
|
||||
}
|
||||
cloned.Set(keyString, value)
|
||||
}
|
||||
|
||||
return cloned
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user