private boolean matchesExpression(String toSearch,String expression){
  if (toSearch == null || expression == null) {
    return false;
  }
  int toSearchIndex=0;
  int exprIndex=0;
  while ((exprIndex < expression.length()) && (toSearchIndex < toSearch.length())) {
    if (expression.charAt(exprIndex) == CHAR_MATCH_ESCAPE) {
      exprIndex++;
      if (exprIndex == expression.length()) {
        return false;
      }
      if (expression.charAt(exprIndex) == toSearch.charAt(toSearchIndex)) {
        exprIndex++;
        toSearchIndex++;
      }
 else {
        return false;
      }
    }
 else     if (expression.charAt(exprIndex) == CHAR_MATCH_MANY) {
      String partExpr=expression.substring(exprIndex + 1);
      for (int j=toSearchIndex; j <= toSearch.length(); j++) {
        if (matchesExpression(toSearch.substring(j),partExpr)) {
          return true;
        }
      }
      return false;
    }
 else     if (expression.charAt(exprIndex) == CHAR_MATCH_ONE) {
      return matchesExpression(toSearch.substring(toSearchIndex + 1),expression.substring(exprIndex + 1));
    }
 else     if (toSearch.charAt(toSearchIndex) == expression.charAt(exprIndex)) {
      toSearchIndex++;
      exprIndex++;
    }
 else {
      return false;
    }
  }
  for (int i=exprIndex; i < expression.length(); i++) {
    if (expression.charAt(i) != CHAR_MATCH_MANY) {
      break;
    }
    exprIndex++;
  }
  return ((toSearch.length() == toSearchIndex) && (expression.length() == exprIndex));
}

private boolean matchesExpression ( String toSearch , String expression ) { if ( toSearch == null || expression == null ) { return false ; } int toSearchIndex = 0 ; int exprIndex = 0 ; while ( ( exprIndex < expression . length ( ) ) && ( toSearchIndex < toSearch . length ( ) ) ) { if ( expression . charAt ( exprIndex ) == CHAR_MATCH_ESCAPE ) { exprIndex ++ ; if ( exprIndex == expression . length ( ) ) { return false ; } if ( expression . charAt ( exprIndex ) == toSearch . charAt ( toSearchIndex ) ) { exprIndex ++ ; toSearchIndex ++ ; } else { return false ; } } else if ( expression . charAt ( exprIndex ) == CHAR_MATCH_MANY ) { String partExpr = expression . substring ( exprIndex + 1 ) ; for ( int j = toSearchIndex ; j <= toSearch . length ( ) ; j ++ ) { if ( matchesExpression ( toSearch . substring ( j ) , partExpr ) ) { return true ; } } return false ; } else if ( expression . charAt ( exprIndex ) == CHAR_MATCH_ONE ) { return matchesExpression ( toSearch . substring ( toSearchIndex + 1 ) , expression . substring ( exprIndex + 1 ) ) ; } else if ( toSearch . charAt ( toSearchIndex ) == expression . charAt ( exprIndex ) ) { toSearchIndex ++ ; exprIndex ++ ; } else { return false ; } } for ( int i = exprIndex ; i < expression . length ( ) ; i ++ ) { if ( expression . charAt ( i ) != CHAR_MATCH_MANY ) { break ; } exprIndex ++ ; } return ( ( toSearch . length ( ) == toSearchIndex ) && ( expression . length ( ) == exprIndex ) ) ; }
checks if the tosearch string matches the given expression .
