1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-06 08:39:09 +02:00

Feature/#5 collect keyword alt (#141)

Implemented COLLECT key word
This commit is contained in:
Tim Voronov
2018-10-24 21:30:05 -04:00
committed by GitHub
parent b02c554214
commit 549b4abd3b
67 changed files with 4913 additions and 2811 deletions

View File

@@ -279,6 +279,17 @@ func Unmarshal(value json.RawMessage) (core.Value, error) {
return Parse(o), nil
}
func IsCloneable(value core.Value) Boolean {
switch value.Type() {
case core.ArrayType:
return NewBoolean(true)
case core.ObjectType:
return NewBoolean(true)
default:
return NewBoolean(false)
}
}
func ToBoolean(input core.Value) core.Value {
switch input.Type() {
case core.BooleanType:
@@ -296,13 +307,54 @@ func ToBoolean(input core.Value) core.Value {
}
}
func IsCloneable(value core.Value) Boolean {
switch value.Type() {
func ToArray(input core.Value) core.Value {
switch input.Type() {
case core.BooleanType,
core.IntType,
core.FloatType,
core.StringType,
core.DateTimeType:
return NewArrayWith(input)
case core.HTMLElementType,
core.HTMLDocumentType:
val := input.(HTMLNode)
attrs := val.GetAttributes()
obj, ok := attrs.(*Object)
if !ok {
return NewArray(0)
}
arr := NewArray(int(obj.Length()))
obj.ForEach(func(value core.Value, key string) bool {
arr.Push(value)
return true
})
return obj
case core.ArrayType:
return NewBoolean(true)
return input.Copy()
case core.ObjectType:
return NewBoolean(true)
obj, ok := input.(*Object)
if !ok {
return NewArray(0)
}
arr := NewArray(int(obj.Length()))
obj.ForEach(func(value core.Value, key string) bool {
arr.Push(value)
return true
})
return obj
default:
return NewBoolean(false)
return NewArray(0)
}
}