| 1423 | |
| 1424 | |
| 1425 | int diff_match_patch::match_main(const QString &text, const QString &pattern, |
| 1426 | int loc) { |
| 1427 | // Check for null inputs. |
| 1428 | if (text.isNull() || pattern.isNull()) { |
| 1429 | throw "Null inputs. (match_main)"; |
| 1430 | } |
| 1431 | |
| 1432 | loc = std::max(0, std::min(loc, text.length())); |
| 1433 | if (text == pattern) { |
| 1434 | // Shortcut (potentially not guaranteed by the algorithm) |
| 1435 | return 0; |
| 1436 | } else if (text.isEmpty()) { |
| 1437 | // Nothing to match. |
| 1438 | return -1; |
| 1439 | } else if (loc + pattern.length() <= text.length() |
| 1440 | && safeMid(text, loc, pattern.length()) == pattern) { |
| 1441 | // Perfect match at the perfect spot! (Includes case of null pattern) |
| 1442 | return loc; |
| 1443 | } else { |
| 1444 | // Do a fuzzy compare. |
| 1445 | return match_bitap(text, pattern, loc); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | int diff_match_patch::match_bitap(const QString &text, const QString &pattern, |