int checkIfSargableAndRemoveEscapeChars(ExecutionContext context,StringBuffer buffer){
  int len=buffer.length();
  int wildcardPosition=-1;
  for (int i=0; i < len; ++i) {
    char ch=buffer.charAt(i);
    if (ch == UNDERSCORE) {
      context.cachePut(wildcardTypeKey,WILDCARD_UNDERSCORE);
      wildcardPosition=i;
      break;
    }
 else     if (ch == PERCENT) {
      context.cachePut(wildcardTypeKey,WILDCARD_PERCENT);
      wildcardPosition=i;
      break;
    }
 else     if (ch == BACKSLASH) {
      if (i + 1 < len) {
        if (buffer.charAt(i + 1) == PERCENT || buffer.charAt(i + 1) == UNDERSCORE) {
          wildcardPosition=-1;
        }
        buffer.deleteCharAt(i);
        len--;
      }
    }
  }
  return wildcardPosition;
}

int checkIfSargableAndRemoveEscapeChars ( ExecutionContext context , StringBuffer buffer ) { int len = buffer . length ( ) ; int wildcardPosition = - 1 ; for ( int i = 0 ; i < len ; ++ i ) { char ch = buffer . charAt ( i ) ; if ( ch == UNDERSCORE ) { context . cachePut ( wildcardTypeKey , WILDCARD_UNDERSCORE ) ; wildcardPosition = i ; break ; } else if ( ch == PERCENT ) { context . cachePut ( wildcardTypeKey , WILDCARD_PERCENT ) ; wildcardPosition = i ; break ; } else if ( ch == BACKSLASH ) { if ( i + 1 < len ) { if ( buffer . charAt ( i + 1 ) == PERCENT || buffer . charAt ( i + 1 ) == UNDERSCORE ) { wildcardPosition = - 1 ; } buffer . deleteCharAt ( i ) ; len -- ; } } } return wildcardPosition ; }
checks if index can be used for strings with wildcards . two wild cards are supported % and _ . the wildcard could be at any index position of the string .
