2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-16 01:29:26 +00:00
|
|
|
|
2021-02-04 22:49:40 +00:00
|
|
|
import "gopkg.in/yaml.v3"
|
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
2020-10-16 01:29:26 +00:00
|
|
|
log.Debugf("-- equalsOperation")
|
2021-04-13 00:42:20 +00:00
|
|
|
return crossFunction(d, context, expressionNode, isEquals(false), false)
|
2020-10-16 01:29:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 22:54:03 +00:00
|
|
|
func isEquals(flip bool) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
|
|
|
return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
|
|
|
value := false
|
2020-10-16 01:29:26 +00:00
|
|
|
|
2021-02-04 22:54:03 +00:00
|
|
|
lhsNode := unwrapDoc(lhs.Node)
|
|
|
|
rhsNode := unwrapDoc(rhs.Node)
|
2021-01-11 22:40:37 +00:00
|
|
|
|
2021-02-04 22:54:03 +00:00
|
|
|
if lhsNode.Tag == "!!null" {
|
|
|
|
value = (rhsNode.Tag == "!!null")
|
|
|
|
} else if lhsNode.Kind == yaml.ScalarNode && rhsNode.Kind == yaml.ScalarNode {
|
|
|
|
value = matchKey(lhsNode.Value, rhsNode.Value)
|
|
|
|
}
|
|
|
|
log.Debugf("%v == %v ? %v", NodeToString(lhs), NodeToString(rhs), value)
|
|
|
|
if flip {
|
|
|
|
value = !value
|
|
|
|
}
|
|
|
|
return createBooleanCandidate(lhs, value), nil
|
2020-10-16 01:29:26 +00:00
|
|
|
}
|
2021-02-04 22:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func notEqualsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
|
|
log.Debugf("-- equalsOperation")
|
2021-04-13 00:42:20 +00:00
|
|
|
return crossFunction(d, context, expressionNode, isEquals(true), false)
|
2020-10-16 01:29:26 +00:00
|
|
|
}
|