pnoltes commented on a change in pull request #385:
URL: https://github.com/apache/celix/pull/385#discussion_r773252664
##########
File path: libs/utils/src/filter.c
##########
@@ -725,4 +724,71 @@ const char* celix_filter_findAttribute(const
celix_filter_t *filter, const char
}
}
return result;
+}
+
+static bool hasMandatoryEqualsValueAttribute(const celix_filter_t *filter,
const char *attribute, bool negated, bool optional) {
+ bool equalsValueAttribute = false;
+
+ if (filter != NULL && attribute != NULL) {
+ if (filter->operand == CELIX_FILTER_OPERAND_AND || filter->operand ==
CELIX_FILTER_OPERAND_OR || filter->operand == CELIX_FILTER_OPERAND_NOT) {
+ size_t size = celix_arrayList_size(filter->children);
Review comment:
celix_arrayList_size returns a `int` not `size_t`. Note that maybe a
`size_t` should have been better, but to prevent breaking the API is kept at
`int`.
So imo should should be:
```
int size = celix_arrayList_size(filter->children);
for (int i = 0; i < size; ++i) {
...
```
##########
File path: libs/utils/src/filter.c
##########
@@ -725,4 +724,71 @@ const char* celix_filter_findAttribute(const
celix_filter_t *filter, const char
}
}
return result;
+}
+
+static bool hasMandatoryEqualsValueAttribute(const celix_filter_t *filter,
const char *attribute, bool negated, bool optional) {
+ bool equalsValueAttribute = false;
+
+ if (filter != NULL && attribute != NULL) {
+ if (filter->operand == CELIX_FILTER_OPERAND_AND || filter->operand ==
CELIX_FILTER_OPERAND_OR || filter->operand == CELIX_FILTER_OPERAND_NOT) {
+ size_t size = celix_arrayList_size(filter->children);
+ for (unsigned int i = 0; i < size; ++i) {
+
+ if (filter->operand == CELIX_FILTER_OPERAND_NOT) {
+ negated = !negated;
+ } else if (filter->operand == CELIX_FILTER_OPERAND_OR) {
+ optional = true;
+ }
+
+ celix_filter_t *child = celix_arrayList_get(filter->children,
i);
+
+ equalsValueAttribute = hasMandatoryEqualsValueAttribute(child,
attribute, negated, optional);
+
+ if (equalsValueAttribute) {
+ break;
+ }
+ }
+ } else if (filter->operand == CELIX_FILTER_OPERAND_EQUAL) {
+ equalsValueAttribute = (strncmp(filter->attribute, attribute, 1024
* 1024) == 0) && (!negated) && (!optional);
+ }
+ }
+
+ return equalsValueAttribute;
+}
+
+bool celix_filter_hasMandatoryEqualsValueAttribute(const celix_filter_t
*filter, const char *attribute) {
+ return hasMandatoryEqualsValueAttribute(filter, attribute, false, false);
+}
+
+static bool hasMandatoryNegatedPresenceAttribute(const celix_filter_t *filter,
const char *attribute, bool negated, bool optional) {
+ bool negatedPresenceAttribute = false;
+
+ if (filter != NULL && attribute != NULL) {
+ if (filter->operand == CELIX_FILTER_OPERAND_AND || filter->operand ==
CELIX_FILTER_OPERAND_OR || filter->operand == CELIX_FILTER_OPERAND_NOT) {
+ size_t size = celix_arrayList_size(filter->children);
Review comment:
same here `celix_arrayList_size` return `int` not `size_t`
##########
File path: libs/utils/include/celix/Filter.h
##########
@@ -118,6 +118,32 @@ namespace celix {
return celix_filter_findAttribute(cFilter.get(),
attributeKey.c_str()) != nullptr;
}
+ /**
+ * @brief Check whether the filter indicates the mandatory presence of
an attribute with a specific value for the provided attribute key.
+ *
+ * Example:
+ * using this method for attribute key "key1" on filter
"(key1=value1)" yields true.
+ * using this method for attribute key "key1" on filter
"(!(key1=value1))" yields false.
+ * using this method for attribute key "key1" on filter
"(key1>=value1)" yields false.
+ * using this method for attribute key "key1" on filter
"(|(key1=value1)(key2=value2))" yields false.
+ */
+ [[nodiscard]] bool hasMandatoryEqualsValueAttribute(const std::string&
attributeKey) const {
Review comment:
Can the `const std::string&` be changed to `std::string_view`. This way
the method accepts `std::string`, `const char*`, `std::string_view` and even
constexpr `std::string_view`.
Something like:
```
[[nodiscard]] bool hasMandatoryEqualsValueAttribute(std::string_view
attributeKey) const {
return celix_filter_hasMandatoryEqualsValueAttribute(cFilter.get(),
attributeKey.data());
}
```
same for `hasMandatoryNegatedPresenceAttribute`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]