Added ndn_Exclude_matches.
diff --git a/ndn-cpp/c/interest.c b/ndn-cpp/c/interest.c
index 361412e..15553b4 100644
--- a/ndn-cpp/c/interest.c
+++ b/ndn-cpp/c/interest.c
@@ -16,3 +16,57 @@
// The components are equal length. Just do a byte compare.
return ndn_memcmp(component1->value, component2->value, component1->valueLength);
}
+
+int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component)
+{
+ unsigned int i;
+ for (i = 0; i < self->nEntries; ++i) {
+ if (self->entries[i].type == ndn_Exclude_ANY) {
+ struct ndn_ExcludeEntry *lowerBound = 0;
+ if (i > 0)
+ lowerBound = self->entries + (i - 1);
+
+ // Find the upper bound, possibly skipping over multiple ANY in a row.
+ unsigned int iUpperBound;
+ struct ndn_ExcludeEntry *upperBound = 0;
+ for (iUpperBound = i + 1; iUpperBound < self->nEntries; ++iUpperBound) {
+ if (self->entries[iUpperBound].type == ndn_Exclude_COMPONENT) {
+ upperBound = self->entries + iUpperBound;
+ break;
+ }
+ }
+
+ // If lowerBound != 0, we already checked component equals lowerBound on the last pass.
+ // If upperBound != 0, we will check component equals upperBound on the next pass.
+ if (upperBound != 0) {
+ if (lowerBound != 0) {
+ if (ndn_Exclude_compareComponents(component, &lowerBound->component) > 0 &&
+ ndn_Exclude_compareComponents(component, &upperBound->component) < 0)
+ return 1;
+ }
+ else {
+ if (ndn_Exclude_compareComponents(component, &upperBound->component) < 0)
+ return 1;
+ }
+
+ // Make i equal iUpperBound on the next pass.
+ i = iUpperBound - 1;
+ }
+ else {
+ if (lowerBound != 0) {
+ if (ndn_Exclude_compareComponents(component, &lowerBound->component) > 0)
+ return 1;
+ }
+ else
+ // this.values has only ANY.
+ return 1;
+ }
+ }
+ else {
+ if (ndn_Exclude_compareComponents(component, &self->entries[i].component) == 0)
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/ndn-cpp/c/interest.h b/ndn-cpp/c/interest.h
index c3a1647..42b9c62 100644
--- a/ndn-cpp/c/interest.h
+++ b/ndn-cpp/c/interest.h
@@ -49,7 +49,7 @@
};
/**
* Initialize an ndn_Exclude struct with the entries array.
- * @param self pointer to the ndn_Exclude struct
+ * @param self A pointer to the ndn_Exclude struct.
* @param entries the pre-allocated array of ndn_ExcludeEntry
* @param maxEntries the number of elements in the allocated entries array
*/
@@ -69,6 +69,14 @@
*/
int ndn_Exclude_compareComponents(struct ndn_NameComponent *component1, struct ndn_NameComponent *component2);
+/**
+ * Check if the component matches any of the exclude criteria.
+ * @param self A pointer to the ndn_Exclude struct.
+ * @param component A pointer to the name component to check.
+ * @return 1 if the component matches any of the exclude criteria, otherwise 0.
+ */
+int ndn_Exclude_matches(struct ndn_Exclude *self, struct ndn_NameComponent *component);
+
enum {
ndn_Interest_CHILD_SELECTOR_LEFT = 0,
ndn_Interest_CHILD_SELECTOR_RIGHT = 1,