Support surrounding search strings in quotations

This commit is contained in:
drdev
2014-11-13 01:34:15 +00:00
parent a9865cf7bb
commit acdb847b66
2 changed files with 55 additions and 9 deletions

View File

@@ -16,6 +16,15 @@ Forge now includes many of the new Commander 2014 cards. It may take a few days/
The game now correctly calculates whether an attack declaration is legal, based upon the restrictions and requirements present on the possible attacking creatures. AI support is not yet fully implemented, but the AI can always default to a legal attack declaration.
- Support for surrounding search expressions with quotations -
You can now wrap all or part of a search expression in the Deck Editor or other ItemManagers in quotations to prevent matching on anything that doesn't contain all words within the quotes in order.
For example, while searching for this expression:
creatures you don't control
will match on any cards that contains all 4 of those words in any configuration (24/14330 implemented), this expression:
"creatures you don't control"
will only match on cards that contain those exact words in that exact order with no other words in between (4/14330 implemented).
---------
New Cards
---------

View File

@@ -39,7 +39,6 @@ public class SFilterUtil {
}
if (BooleanExpression.isExpression(text)) {
BooleanExpression expression = new BooleanExpression(text, inName, inType, inText, inCost);
try {
@@ -47,15 +46,14 @@ public class SFilterUtil {
if (filter != null) {
return Predicates.compose(invert ? Predicates.not(filter) : filter, PaperCard.FN_GET_RULES);
}
} catch (Exception ignored) {
}
catch (Exception ignored) {
ignored.printStackTrace();
//Continue with standard filtering if the expression is not valid.
}
}
String[] splitText = text.replaceAll(",", "").replaceAll(" ", " ").split(" ");
List<String> splitText = getSplitText(text);
List<Predicate<CardRules>> terms = new ArrayList<>();
for (String s : splitText) {
List<Predicate<CardRules>> subands = new ArrayList<>();
@@ -72,6 +70,45 @@ public class SFilterUtil {
return Predicates.compose(textFilter, PaperCard.FN_GET_RULES);
}
private static List<String> getSplitText(String text) {
boolean inQuotes = false;
String entry = "";
List<String> splitText = new ArrayList<String>();
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
switch (ch) {
case ' ':
if (!inQuotes) { //if not in quotes, end current entry
if (entry.length() > 0) {
splitText.add(entry);
entry = "";
}
continue;
}
break;
case '"':
inQuotes = !inQuotes;
continue; //don't append quotation character itself
case '\\':
if (i < text.length() - 1 && text.charAt(i + 1) == '"') {
ch = '"'; //allow appending escaped quotation character
i++; //prevent chaging inQuotes for that character
}
break;
case ',':
if (!inQuotes) { //ignore commas outside quotes
continue;
}
break;
}
entry += ch;
}
if (entry.length() > 0) {
splitText.add(entry);
}
return splitText;
}
public static <T extends InventoryItem> Predicate<T> buildItemTextFilter(String text) {
if (text.trim().isEmpty()) {
return Predicates.alwaysTrue();
@@ -81,10 +118,10 @@ public class SFilterUtil {
}
private static class ItemTextPredicate<T extends InventoryItem> implements Predicate<T> {
private final String[] splitText;
private final List<String> splitText;
private ItemTextPredicate(String text) {
splitText = text.toLowerCase().replaceAll(",", "").replaceAll(" ", " ").split(" ");
splitText = getSplitText(text.toLowerCase());
}
@Override