Skip to content

Commit

Permalink
Add tags list.find_partial, find_all_partial
Browse files Browse the repository at this point in the history
Further find methods
  • Loading branch information
mcmonkey4eva committed Oct 19, 2014
1 parent 085c3cf commit 97c75bb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -712,6 +712,25 @@ else if (dEntity.matches(get(n))) {
}
}

// <--[tag]
// @attribute <li@list.find_all_partial[<element>]>
// @returns dList(Element(Number))
// @description
// returns all the numbered locations of elements within a list,
// or an empty list if the list does not contain that item.
// EG, .find[two] on a list of "one|two|three|two" will return "2|4".
// TODO: Take multiple inputs? Or a regex?
// -->
if (attribute.startsWith("find_all_partial") &&
attribute.hasContext(1)) {
dList positions = new dList();
for (int i = 0; i < size(); i++) {
if (get(i).toUpperCase().contains(attribute.getContext(1).toUpperCase()))
positions.add(String.valueOf(i + 1));
}
return positions.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.find_all[<element>]>
// @returns dList(Element(Number))
Expand All @@ -731,6 +750,24 @@ else if (dEntity.matches(get(n))) {
return positions.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.find_partial[<element>]>
// @returns Element(Number)
// @description
// returns the numbered location of the first partially matching element within a list,
// or -1 if the list does not contain that item.
// EG, .find[two] on a list of "one|two|three" will return "2".
// TODO: Take multiple inputs? Or a regex?
// -->
if (attribute.startsWith("find_partial") &&
attribute.hasContext(1)) {
for (int i = 0; i < size(); i++) {
if (get(i).toUpperCase().contains(attribute.getContext(1).toUpperCase()))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
return new Element(-1).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.find[<element>]>
// @returns Element(Number)
Expand Down

0 comments on commit 97c75bb

Please sign in to comment.