yq/pkg/yqlib/operator_equals.go

22 lines
675 B
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-10-16 01:29:26 +00:00
func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
2020-10-16 01:29:26 +00:00
log.Debugf("-- equalsOperation")
return crossFunction(d, context, expressionNode, isEquals)
2020-10-16 01:29:26 +00:00
}
func isEquals(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
2020-10-20 05:27:30 +00:00
value := false
2020-10-16 01:29:26 +00:00
2021-01-12 23:00:51 +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
}