code: public static int match_main(String text, String pattern, int loc) {
          // Check for null inputs.
          if (text == null || pattern == null) {
              throw new IllegalArgumentException("Null inputs. (match_main)");
          }
  
          loc = Math.max(0, Math.min(loc, text.length()));
          if (text.equals(pattern)) {
              // Shortcut (potentially not guaranteed by the algorithm)
              return 0;
          } else if (text.length() == 0) {
              // Nothing to match.
              return -1;
          } else if (loc + pattern.length() <= text.length()
                  && text.substring(loc, loc + pattern.length()).equals(pattern)) {
              // Perfect match at the perfect spot! (Includes case of null
              // pattern)
              return loc;
          } else {
              // Do a fuzzy compare.
              return match_bitap(text, pattern, loc);
          }
      }
docs: Locate the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if
  no match found.
  
  @param text
  The text to search.
  @param pattern
  The pattern to search for.
  @param loc
  The location to search around.
  @return Best match index or -1.