* Converts a `value_query` in the above grammar, with the given path, to a predicate * The predicate is returned by appending to `out_terms` zero or more predicates which, * anded together, have the semantics of the given value_query. */
| 86 | * anded together, have the semantics of the given value_query. |
| 87 | */ |
| 88 | void valueQueryToPredicates(bson::BSONObj const& value_query, |
| 89 | std::string const& path, |
| 90 | std::vector<Reference<IPredicate>>& out_terms) { |
| 91 | std::string regex_options; // hacky special handling of { $option, $regex } |
| 92 | for (auto it = value_query.begin(); it.more();) { |
| 93 | auto sub = it.next(); |
| 94 | if (std::string(sub.fieldName()) == "$options") { |
| 95 | regex_options = sub.String(); |
| 96 | } else { |
| 97 | out_terms.push_back(ExtValueOperator::toPredicate(sub.fieldName(), path, sub)); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // $options is applied to "$regex" so we don't have to create a Value Operator for it |
| 102 | // but we still need to find the predicate that is RegEx and apply the options |
| 103 | for (auto itCur = out_terms.rbegin(); !(itCur == out_terms.rend()); ++itCur) { |
| 104 | if (auto pAnyPredicate = dynamic_cast<AnyPredicate*>(itCur->getPtr())) { |
| 105 | if (auto pRegExPredicate = dynamic_cast<RegExPredicate*>(pAnyPredicate->pred.getPtr())) { |
| 106 | pRegExPredicate->setOptions(regex_options); |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Converts a `value_query` in the above grammar, with the given path, to a predicate. |
no test coverage detected