yq/pkg/yqlib/treeops/operator_equals.go

23 lines
630 B
Go
Raw Normal View History

2020-10-16 01:29:26 +00:00
package treeops
import (
2020-10-21 01:54:58 +00:00
"container/list"
2020-10-16 01:29:26 +00:00
)
2020-10-21 01:54:58 +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
2020-10-20 05:27:30 +00:00
if lhs.Node.Tag == "!!null" {
value = (rhs.Node.Tag == "!!null")
} else {
value = Match(lhs.Node.Value, rhs.Node.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
}