public static boolean matches ( String text , String pattern ) { if ( text == null ) { throw new IllegalArgumentException ( "text cannot be null" ) ; } text += ' ' ; pattern += ' ' ; int N = pattern . length ( ) ; boolean [ ] states = new boolean [ N + 1 ] ; boolean [ ] old = new boolean [ N + 1 ] ; old [ 0 ] = true ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { char c = text . charAt ( i ) ; states = new boolean [ N + 1 ] ; // initialized to false for ( int j = 0 ; j < N ; j ++ ) { char p = pattern . charAt ( j ) ; // hack to handle *'s that match 0 characters if ( old [ j ] && ( p == WILDCARD ) ) old [ j + 1 ] = true ; if ( old [ j ] && ( p == c ) ) states [ j + 1 ] = true ; if ( old [ j ] && ( p == WILDCARD ) ) states [ j ] = true ; if ( old [ j ] && ( p == WILDCARD ) ) states [ j + 1 ] = true ; } old = states ; } return states [ N ] ; }
Performs a wildcard matching for the text and pattern provided .