diff options
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 598ecc2e..710bdd6c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -429,6 +429,33 @@ public class NEUManager { } /** + * SearchString but with AND | OR support + */ + + public boolean multiSearchString(String match, String query) { + boolean totalMatches = false; + + StringBuilder query2 = new StringBuilder(); + char lastOp = '|'; + for (char c : query.toCharArray()) { + if (c == '|' || c == '&') { + boolean matches = searchString(match, query2.toString()); + totalMatches = lastOp == '|' ? totalMatches || matches : totalMatches && matches; + + query2 = new StringBuilder(); + lastOp = c; + } else { + query2.append(c); + } + } + + boolean matches = searchString(match, query2.toString()); + totalMatches = lastOp == '|' ? totalMatches || matches : totalMatches && matches; + + return totalMatches; + } + + /** * Searches a string for a query. This method is used to mimic the behaviour of the more complex map-based search * function. This method is used for the chest-item-search feature. */ @@ -490,7 +517,7 @@ public class NEUManager { public boolean doesStackMatchSearch(ItemStack stack, String query) { if (query.startsWith("title:")) { query = query.substring(6); - return searchString(stack.getDisplayName(), query); + return multiSearchString(stack.getDisplayName(), query); } else if (query.startsWith("desc:")) { query = query.substring(5); String lore = ""; @@ -504,7 +531,7 @@ public class NEUManager { } } } - return searchString(lore, query); + return multiSearchString(lore, query); } else if (query.startsWith("id:")) { query = query.substring(3); String internalName = getInternalNameForItem(stack); @@ -516,9 +543,11 @@ public class NEUManager { for (char c : query.toCharArray()) { sb.append(c).append(" "); } - result = result || searchString(stack.getDisplayName(), sb.toString()); + result = result || multiSearchString(stack.getDisplayName(), sb.toString()); } - result = result || searchString(stack.getDisplayName(), query); + + + result = result || multiSearchString(stack.getDisplayName(), query); String lore = ""; NBTTagCompound tag = stack.getTagCompound(); @@ -532,7 +561,7 @@ public class NEUManager { } } - result = result || searchString(lore, query); + result = result || multiSearchString(lore, query); return result; } |