yq/pkg/yqlib/operator_equals.go

26 lines
692 B
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-16 01:29:26 +00:00
import (
2020-10-21 01:54:58 +00:00
"container/list"
2020-10-16 01:29:26 +00:00
)
func equalsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathTreeNode) (*list.List, error) {
2020-10-16 01:29:26 +00:00
log.Debugf("-- equalsOperation")
2020-10-20 05:27:30 +00:00
return crossFunction(d, matchingNodes, pathNode, isEquals)
2020-10-16 01:29:26 +00:00
}
2020-10-20 05:27:30 +00:00
func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
value := false
2020-10-16 01:29:26 +00:00
lhsNode := UnwrapDoc(lhs.Node)
rhsNode := UnwrapDoc(rhs.Node)
if lhsNode.Tag == "!!null" {
value = (rhsNode.Tag == "!!null")
2020-10-20 05:27:30 +00:00
} else {
value = matchKey(lhsNode.Value, rhsNode.Value)
2020-10-16 01:29:26 +00:00
}
2020-10-20 05:27:30 +00:00
log.Debugf("%v == %v ? %v", NodeToString(lhs), NodeToString(rhs), value)
return createBooleanCandidate(lhs, value), nil
2020-10-16 01:29:26 +00:00
}