diff --git a/src/java/mmm/tech/base/workbench/TBWBGui.java b/src/java/mmm/tech/base/workbench/TBWBGui.java index f556343..1325443 100644 --- a/src/java/mmm/tech/base/workbench/TBWBGui.java +++ b/src/java/mmm/tech/base/workbench/TBWBGui.java @@ -4,6 +4,9 @@ package mmm.tech.base.workbench; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.lwjgl.input.Keyboard; @@ -224,10 +227,42 @@ public class TBWBGui this.recipes.clear( ); } + Predicate< String > matcher; + if ( newText.charAt( 0 ) == '=' && newText.length( ) > 1 ) { + final String searchText = newText.substring( 1 ); + matcher = ( x ) -> x.equals( searchText ); + } else { + Pattern pattern; + if ( newText.charAt( 0 ) == '/' && newText.length( ) > 1 ) { + try { + pattern = Pattern.compile( newText.substring( 1 ) , + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE ); + } catch ( final PatternSyntaxException e ) { + pattern = null; + } + } else { + pattern = null; + } + + if ( pattern != null ) { + matcher = pattern.asPredicate( ); + } else { + final String[] parts = newText.split( "\\s+" ); + matcher = ( x ) -> { + for ( int i = 0 ; i < parts.length ; i++ ) { + if ( !x.contains( parts[ i ] ) ) { + return false; + } + } + return true; + }; + } + } + final int nRecipes = fullList.size( ); for ( int i = 0 ; i < nRecipes ; i++ ) { final I_CraftingRecipeWrapper recipe = fullList.get( i ); - if ( I18n.format( recipe.getName( ) ).toLowerCase( ).contains( newText ) ) { + if ( matcher.test( I18n.format( recipe.getName( ) ).toLowerCase( ) ) ) { this.recipes.add( recipe ); } }