* Matches the given unformatted text against the given formatted text exactly and validates the match. * Skips whitespace. Skips fuzzy (defined by isFuzzy()) characters using the given @p fuzzyMatcher. * @return whether the match was successful. */
| 915 | * @return whether the match was successful. |
| 916 | */ |
| 917 | bool matchFormattedText(const QString& text, QStringView formattedText, CompleteFuzzyMatcher&& fuzzyMatcher, |
| 918 | bool isEndAContextTextBoundary) |
| 919 | { |
| 920 | // This intermediary view guarantees that iterators passed to PrefixMatcher() are of the same type. |
| 921 | const QStringView textView = text; |
| 922 | PrefixMatcher prefixMatcher(textView.cbegin(), textView.cend(), formattedText.cbegin(), formattedText.cend(), |
| 923 | fuzzyMatcher); |
| 924 | auto result = prefixMatcher.match(isEndAContextTextBoundary); |
| 925 | if (!result.hasMatched) { |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | // Skip to verify that only whitespace and fuzzy characters remain in the formatted text after result.matchEnd. |
| 930 | // Satisfy the preconditions of skipFuzzyAndWhitespace() by skipping whitespace |
| 931 | // and checking whether the range is empty before calling it. |
| 932 | skipWhitespace(result.matchEnd, formattedText.cend()); |
| 933 | if (result.matchEnd != formattedText.cend()) { |
| 934 | const auto fuzzyResult = |
| 935 | skipFuzzyAndWhitespace(result.matchEnd, formattedText.cend(), fuzzyMatcher, /*isInserted=*/true); |
| 936 | if (fuzzyResult == FuzzyMatchResult::MatchingFailed) { |
| 937 | return false; |
| 938 | } |
| 939 | if (result.matchEnd != formattedText.cend()) { |
| 940 | Q_ASSERT(fuzzyResult == FuzzyMatchResult::NotFuzzy); |
| 941 | qCWarning(UTIL) << "giving up formatting because of a character in formatted text not matched in text:" |
| 942 | << *result.matchEnd; |
| 943 | return false; |
| 944 | } |
| 945 | Q_ASSERT(fuzzyResult == FuzzyMatchResult::Fuzzy); |
| 946 | } |
| 947 | |
| 948 | return fuzzyMatcher.validate(); |
| 949 | } |
| 950 | |
| 951 | QString reverse(QStringView str) |
| 952 | { |
no test coverage detected