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.
(String text, String pattern, int loc)
| 1571 | * @return Best match index or -1. |
| 1572 | */ |
| 1573 | public int match_main(String text, String pattern, int loc) { |
| 1574 | // Check for null inputs. |
| 1575 | if (text == null || pattern == null) { |
| 1576 | throw new IllegalArgumentException("Null inputs. (match_main)"); |
| 1577 | } |
| 1578 | |
| 1579 | loc = Math.max(0, Math.min(loc, text.length())); |
| 1580 | if (text.equals(pattern)) { |
| 1581 | // Shortcut (potentially not guaranteed by the algorithm) |
| 1582 | return 0; |
| 1583 | } else if (text.length() == 0) { |
| 1584 | // Nothing to match. |
| 1585 | return -1; |
| 1586 | } else if (loc + pattern.length() <= text.length() |
| 1587 | && text.substring(loc, loc + pattern.length()).equals(pattern)) { |
| 1588 | // Perfect match at the perfect spot! (Includes case of null pattern) |
| 1589 | return loc; |
| 1590 | } else { |
| 1591 | // Do a fuzzy compare. |
| 1592 | return match_bitap(text, pattern, loc); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | /** |
| 1597 | * Locate the best instance of 'pattern' in 'text' near 'loc' using the |
no test coverage detected