aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-11 13:45:45 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-11 13:45:45 +0100
commitbe52a8f9c260f7953bc8b6b991c476120d8704ad (patch)
treed1d1073b322d2ae4382f75f241000ca7980516d4
parent65cc87b1383f37b4b423d4beb42dfe573c1ba3ea (diff)
downloadgloppers-be52a8f9c260f7953bc8b6b991c476120d8704ad.tar.gz
gloppers-be52a8f9c260f7953bc8b6b991c476120d8704ad.tar.bz2
gloppers-be52a8f9c260f7953bc8b6b991c476120d8704ad.zip
-rw-r--r--src/main/java/com/notnite/gloppers/GlobUtil.java10
-rw-r--r--src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java2
-rw-r--r--src/test/java/com/notnite/gloppers/GlobUtilTest.java13
3 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/com/notnite/gloppers/GlobUtil.java b/src/main/java/com/notnite/gloppers/GlobUtil.java
index 38d0e44..2ae051c 100644
--- a/src/main/java/com/notnite/gloppers/GlobUtil.java
+++ b/src/main/java/com/notnite/gloppers/GlobUtil.java
@@ -4,6 +4,16 @@ import java.util.BitSet;
public class GlobUtil {
+ public static boolean matchGlobSequence(String name, String globs) {
+ int nextSplit, lastSplit = 0;
+ while ((nextSplit = globs.indexOf(',', lastSplit)) > 0) {
+ if (matchGlob(name, globs.substring(lastSplit, nextSplit)))
+ return true;
+ lastSplit = nextSplit + 1;
+ }
+ return matchGlob(name, globs.substring(lastSplit));
+ }
+
/**
* Match a string against a glob.
*/
diff --git a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
index 06eb93e..52cbdcc 100644
--- a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
+++ b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java
@@ -44,7 +44,7 @@ public abstract class HopperBlockEntityMixin {
var itemName = itemRegistryEntry.get().getValue().getPath();
// Check if itemstack matches glob
- if (!GlobUtil.matchGlob(itemName, glob)) return false;
+ if (!GlobUtil.matchGlobSequence(itemName, glob)) return false;
return true;
}
diff --git a/src/test/java/com/notnite/gloppers/GlobUtilTest.java b/src/test/java/com/notnite/gloppers/GlobUtilTest.java
index 064ced1..1ceed6a 100644
--- a/src/test/java/com/notnite/gloppers/GlobUtilTest.java
+++ b/src/test/java/com/notnite/gloppers/GlobUtilTest.java
@@ -6,6 +6,17 @@ import static org.junit.jupiter.api.Assertions.*;
class GlobUtilTest {
@Test
+ public void multiGlobPattern() {
+ assertTrue(GlobUtil.matchGlobSequence("test", "test,foo"));
+ assertTrue(GlobUtil.matchGlobSequence("foo", "test,foo"));
+ assertTrue(GlobUtil.matchGlobSequence("foo", "foo"));
+ assertTrue(GlobUtil.matchGlobSequence("foo", "test,f*"));
+ assertTrue(GlobUtil.matchGlobSequence("foo", "*o,f*"));
+ assertFalse(GlobUtil.matchGlobSequence("baa", "*o,f*"));
+ }
+
+
+ @Test
public void testGlobBeginning() {
assertTrue(GlobUtil.matchGlob("test_id", "*_id"));
assertTrue(GlobUtil.matchGlob("test__id", "*_id"));
@@ -28,7 +39,7 @@ class GlobUtilTest {
}
@Test
- public void testSinglePlaceholder() {
+ public void testSingleGlobPlaceholder() {
assertTrue(GlobUtil.matchGlob("test_id", "tes?_i?"));
}
}