private static int indexOfNextChar(int startingPosition,int stopPosition,String searchIn,String openingMarkers,String closingMarkers,Set<SearchMode> searchMode){
  if (searchIn == null) {
    return -1;
  }
  int searchInLength=searchIn.length();
  if (startingPosition >= searchInLength) {
    return -1;
  }
  char c0=Character.MIN_VALUE;
  char c1=searchIn.charAt(startingPosition);
  char c2=startingPosition + 1 < searchInLength ? searchIn.charAt(startingPosition + 1) : Character.MIN_VALUE;
  for (int i=startingPosition; i <= stopPosition; i++) {
    c0=c1;
    c1=c2;
    c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
    boolean dashDashCommentImmediateEnd=false;
    int markerIndex=-1;
    if (searchMode.contains(SearchMode.ALLOW_BACKSLASH_ESCAPE) && c0 == '\\') {
      i++;
      c1=c2;
      c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
    }
 else     if (searchMode.contains(SearchMode.SKIP_BETWEEN_MARKERS) && (markerIndex=openingMarkers.indexOf(c0)) != -1) {
      int nestedMarkersCount=0;
      char openingMarker=c0;
      char closingMarker=closingMarkers.charAt(markerIndex);
      while (++i <= stopPosition && ((c0=searchIn.charAt(i)) != closingMarker || nestedMarkersCount != 0)) {
        if (c0 == openingMarker) {
          nestedMarkersCount++;
        }
 else         if (c0 == closingMarker) {
          nestedMarkersCount--;
        }
 else         if (searchMode.contains(SearchMode.ALLOW_BACKSLASH_ESCAPE) && c0 == '\\') {
          i++;
        }
      }
      c1=i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE;
      c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
    }
 else     if (searchMode.contains(SearchMode.SKIP_BLOCK_COMMENTS) && c0 == '/' && c1 == '*') {
      if (c2 != '!') {
        i++;
        while (++i <= stopPosition && (searchIn.charAt(i) != '*' || (i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE) != '/')) {
        }
        i++;
      }
 else {
        i++;
        i++;
        int j=1;
        for (; j <= NON_COMMENTS_MYSQL_VERSION_REF_LENGTH; j++) {
          if (i + j >= searchInLength || !Character.isDigit(searchIn.charAt(i + j))) {
            break;
          }
        }
        if (j == NON_COMMENTS_MYSQL_VERSION_REF_LENGTH) {
          i+=NON_COMMENTS_MYSQL_VERSION_REF_LENGTH;
        }
      }
      c1=i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE;
      c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
    }
 else     if (searchMode.contains(SearchMode.SKIP_BLOCK_COMMENTS) && c0 == '*' && c1 == '/') {
      i++;
      c1=c2;
      c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
    }
 else     if (searchMode.contains(SearchMode.SKIP_LINE_COMMENTS) && ((c0 == '-' && c1 == '-' && (Character.isWhitespace(c2) || (dashDashCommentImmediateEnd=c2 == ';') || c2 == Character.MIN_VALUE)) || c0 == '#')) {
      if (dashDashCommentImmediateEnd) {
        i++;
        i++;
        c1=i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE;
        c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
      }
 else {
        while (++i <= stopPosition && (c0=searchIn.charAt(i)) != '\n' && c0 != '\r') {
        }
        c1=i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE;
        if (c0 == '\r' && c1 == '\n') {
          i++;
          c1=i + 1 < searchInLength ? searchIn.charAt(i + 1) : Character.MIN_VALUE;
        }
        c2=i + 2 < searchInLength ? searchIn.charAt(i + 2) : Character.MIN_VALUE;
      }
    }
 else     if (!searchMode.contains(SearchMode.SKIP_WHITE_SPACE) || !Character.isWhitespace(c0)) {
      return i;
    }
  }
  return -1;
}

private static int indexOfNextChar ( int startingPosition , int stopPosition , String searchIn , String openingMarkers , String closingMarkers , Set < SearchMode > searchMode ) { if ( searchIn == null ) { return - 1 ; } int searchInLength = searchIn . length ( ) ; if ( startingPosition >= searchInLength ) { return - 1 ; } char c0 = Character . MIN_VALUE ; char c1 = searchIn . charAt ( startingPosition ) ; char c2 = startingPosition + 1 < searchInLength ? searchIn . charAt ( startingPosition + 1 ) : Character . MIN_VALUE ; for ( int i = startingPosition ; i <= stopPosition ; i ++ ) { c0 = c1 ; c1 = c2 ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; boolean dashDashCommentImmediateEnd = false ; int markerIndex = - 1 ; if ( searchMode . contains ( SearchMode . ALLOW_BACKSLASH_ESCAPE ) && c0 == '\\' ) { i ++ ; c1 = c2 ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } else if ( searchMode . contains ( SearchMode . SKIP_BETWEEN_MARKERS ) && ( markerIndex = openingMarkers . indexOf ( c0 ) ) != - 1 ) { int nestedMarkersCount = 0 ; char openingMarker = c0 ; char closingMarker = closingMarkers . charAt ( markerIndex ) ; while ( ++ i <= stopPosition && ( ( c0 = searchIn . charAt ( i ) ) != closingMarker || nestedMarkersCount != 0 ) ) { if ( c0 == openingMarker ) { nestedMarkersCount ++ ; } else if ( c0 == closingMarker ) { nestedMarkersCount -- ; } else if ( searchMode . contains ( SearchMode . ALLOW_BACKSLASH_ESCAPE ) && c0 == '\\' ) { i ++ ; } } c1 = i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } else if ( searchMode . contains ( SearchMode . SKIP_BLOCK_COMMENTS ) && c0 == '/' && c1 == '*' ) { if ( c2 != '!' ) { i ++ ; while ( ++ i <= stopPosition && ( searchIn . charAt ( i ) != '*' || ( i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ) != '/' ) ) { } i ++ ; } else { i ++ ; i ++ ; int j = 1 ; for ( ; j <= NON_COMMENTS_MYSQL_VERSION_REF_LENGTH ; j ++ ) { if ( i + j >= searchInLength || ! Character . isDigit ( searchIn . charAt ( i + j ) ) ) { break ; } } if ( j == NON_COMMENTS_MYSQL_VERSION_REF_LENGTH ) { i += NON_COMMENTS_MYSQL_VERSION_REF_LENGTH ; } } c1 = i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } else if ( searchMode . contains ( SearchMode . SKIP_BLOCK_COMMENTS ) && c0 == '*' && c1 == '/' ) { i ++ ; c1 = c2 ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } else if ( searchMode . contains ( SearchMode . SKIP_LINE_COMMENTS ) && ( ( c0 == '-' && c1 == '-' && ( Character . isWhitespace ( c2 ) || ( dashDashCommentImmediateEnd = c2 == ';' ) || c2 == Character . MIN_VALUE ) ) || c0 == '#' ) ) { if ( dashDashCommentImmediateEnd ) { i ++ ; i ++ ; c1 = i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ; c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } else { while ( ++ i <= stopPosition && ( c0 = searchIn . charAt ( i ) ) != '\n' && c0 != '\r' ) { } c1 = i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ; if ( c0 == '\r' && c1 == '\n' ) { i ++ ; c1 = i + 1 < searchInLength ? searchIn . charAt ( i + 1 ) : Character . MIN_VALUE ; } c2 = i + 2 < searchInLength ? searchIn . charAt ( i + 2 ) : Character . MIN_VALUE ; } } else if ( ! searchMode . contains ( SearchMode . SKIP_WHITE_SPACE ) || ! Character . isWhitespace ( c0 ) ) { return i ; } } return - 1 ; }
finds the position the next character from a string , possibly skipping white space , comments and text between markers .
