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;
+}