public static Pattern parseFilter ( final String spec ) { StringBuffer sb = new StringBuffer ( ) ; for ( int j = 0 ; j < spec . length ( ) ; j ++ ) { char c = spec . charAt ( j ) ; switch ( c ) { case ' ' : sb . append ( "\\." ) ; break ; case ' ' : // test for ** (all directories) if ( j < spec . length ( ) - 1 && spec . charAt ( j + 1 ) == ' ' ) { sb . append ( ".*" ) ; j ++ ; } else { sb . append ( "[^/]*" ) ; } break ; default : sb . append ( c ) ; break ; } } String s = sb . toString ( ) ; try { return Pattern . compile ( s ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Invalid character used in the filter name" , e ) ; } }
Parses a usual filter into a regex pattern .