Skip to content

Commit

Permalink
Cleanup ElementTag.contains tags (#79)
Browse files Browse the repository at this point in the history
* Cleanup  `ElementTag.contains` tags

* Fixes from review
  • Loading branch information
tal5 committed Sep 9, 2022
1 parent 94af38c commit 488eaab
Showing 1 changed file with 21 additions and 38 deletions.
Expand Up @@ -838,8 +838,8 @@ public static void registerTags() {
// -->
tagProcessor.registerStaticTag(ElementTag.class, ListTag.class, "contains_any_case_sensitive_text", (attribute, object, list) -> {
String element = object.element;
for (String list_element : list) {
if (element.contains(list_element)) {
for (String value : list) {
if (element.contains(value)) {
return new ElementTag(true);
}
}
Expand All @@ -855,10 +855,9 @@ public static void registerTags() {
// Returns whether the element contains any of a list of specified elements, case insensitive.
// -->
tagProcessor.registerStaticTag(ElementTag.class, ListTag.class, "contains_any_text", (attribute, object, list) -> {
String element = object.element;
String ellow = CoreUtilities.toLowerCase(element);
for (String list_element : list) {
if (ellow.contains(list_element)) {
String low = object.asLowerString();
for (String value : list) {
if (low.contains(CoreUtilities.toLowerCase(value))) {
return new ElementTag(true);
}
}
Expand All @@ -874,12 +873,7 @@ public static void registerTags() {
// Returns whether the element contains a specified element, case sensitive.
// -->
tagProcessor.registerStaticTag(ElementTag.class, ElementTag.class, "contains_case_sensitive_text", (attribute, object, contains) -> {
if (object.element.contains(contains.asString())) {
return new ElementTag("true");
}
else {
return new ElementTag("false");
}
return new ElementTag(object.asString().contains(contains.asString()));
});
tagProcessor.registerFutureTagDeprecation("contains_case_sensitive_text", "contains_case_sensitive");

Expand All @@ -888,25 +882,15 @@ public static void registerTags() {
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the element contains a specified element, case insensitive. Can use
// regular expression by prefixing the element with regex:
// Returns whether the element contains a specified element, case insensitive.
// Can use regular expression by prefixing the element with 'regex:'.
// -->
tagProcessor.registerStaticTag(ElementTag.class, ElementTag.class, "contains_text", (attribute, object, contains) -> {
String contLow = contains.asLowerString();
if (contLow.startsWith("regex:")) {
if (Pattern.compile(contains.asString().substring(("regex:").length()), Pattern.CASE_INSENSITIVE).matcher(object.element).find()) {
return new ElementTag("true");
}
else {
return new ElementTag("false");
}
}
else if (CoreUtilities.toLowerCase(object.element).contains(contLow)) {
return new ElementTag("true");
}
else {
return new ElementTag("false");
return new ElementTag(Pattern.compile(contains.asString().substring("regex:".length()), Pattern.CASE_INSENSITIVE).matcher(object.asString()).find());
}
return new ElementTag(object.asLowerString().contains(contLow));
});
tagProcessor.registerFutureTagDeprecation("contains_text", "contains");

Expand All @@ -915,17 +899,16 @@ else if (CoreUtilities.toLowerCase(object.element).contains(contLow)) {
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the element contains all of the specified strings, case insensitive.
// Returns whether the element contains all of the specified elements, case insensitive.
// -->
tagProcessor.registerStaticTag(ElementTag.class, ListTag.class, "contains_all_text", (attribute, object, list) -> {
String element = object.element;
String ellow = CoreUtilities.toLowerCase(element);
for (String list_element : list) {
if (!ellow.contains(list_element)) {
return new ElementTag("false");
String low = object.asLowerString();
for (String value : list) {
if (!low.contains(CoreUtilities.toLowerCase(value))) {
return new ElementTag(false);
}
}
return new ElementTag("true");
return new ElementTag(true);
});
tagProcessor.registerFutureTagDeprecation("contains_all_text", "contains_all");

Expand All @@ -934,16 +917,16 @@ else if (CoreUtilities.toLowerCase(object.element).contains(contLow)) {
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the element contains all of the specified strings, case sensitive.
// Returns whether the element contains all of the specified elements, case sensitive.
// -->
tagProcessor.registerStaticTag(ElementTag.class, ListTag.class, "contains_all_case_sensitive_text", (attribute, object, list) -> {
String element = object.element;
for (String list_element : list) {
if (!element.contains(list_element)) {
return new ElementTag("false");
for (String value : list) {
if (!element.contains(value)) {
return new ElementTag(false);
}
}
return new ElementTag("true");
return new ElementTag(true);
});
tagProcessor.registerFutureTagDeprecation("contains_all_case_sensitive_text", "contains_all_case_sensitive");

Expand Down

0 comments on commit 488eaab

Please sign in to comment.