2020-11-03 23:48:43 +00:00
|
|
|
package yqlib
|
2020-10-16 01:29:26 +00:00
|
|
|
|
2021-02-02 07:17:59 +00:00
|
|
|
func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
2024-02-15 22:41:33 +00:00
|
|
|
log.Debugf("equalsOperation")
|
2022-11-13 00:58:21 +00:00
|
|
|
return crossFunction(d, context, expressionNode, isEquals(false), true)
|
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
|
2024-02-15 22:41:33 +00:00
|
|
|
log.Debugf("isEquals cross function")
|
2021-05-09 02:44:05 +00:00
|
|
|
if lhs == nil && rhs == nil {
|
2024-02-15 22:41:33 +00:00
|
|
|
log.Debugf("both are nil")
|
2021-05-09 02:44:05 +00:00
|
|
|
owner := &CandidateNode{}
|
|
|
|
return createBooleanCandidate(owner, !flip), nil
|
|
|
|
} else if lhs == nil {
|
2021-05-16 02:16:10 +00:00
|
|
|
log.Debugf("lhs nil, but rhs is not")
|
2023-10-18 01:11:53 +00:00
|
|
|
value := rhs.Tag == "!!null"
|
2021-05-16 02:16:10 +00:00
|
|
|
if flip {
|
|
|
|
value = !value
|
|
|
|
}
|
|
|
|
return createBooleanCandidate(rhs, value), nil
|
2021-05-09 02:44:05 +00:00
|
|
|
} else if rhs == nil {
|
2021-05-16 02:16:10 +00:00
|
|
|
log.Debugf("lhs not nil, but rhs is")
|
2023-10-18 01:11:53 +00:00
|
|
|
value := lhs.Tag == "!!null"
|
2021-05-16 02:16:10 +00:00
|
|
|
if flip {
|
|
|
|
value = !value
|
|
|
|
}
|
|
|
|
return createBooleanCandidate(lhs, value), nil
|
2021-05-09 02:44:05 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
if lhs.Tag == "!!null" {
|
|
|
|
value = (rhs.Tag == "!!null")
|
|
|
|
} else if lhs.Kind == ScalarNode && rhs.Kind == ScalarNode {
|
|
|
|
value = matchKey(lhs.Value, rhs.Value)
|
2021-02-04 22:54:03 +00:00
|
|
|
}
|
|
|
|
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) {
|
2024-02-15 22:41:33 +00:00
|
|
|
log.Debugf("notEqualsOperator")
|
2021-05-16 04:36:13 +00:00
|
|
|
return crossFunction(d, context.ReadOnlyClone(), expressionNode, isEquals(true), true)
|
2020-10-16 01:29:26 +00:00
|
|
|
}
|