* @brief Compute begin1,begin2,end1,end2 to display byte difference between strings str1 & str2 * @param casitive [in] true for case-sensitive, false for case-insensitive * @param xwhite [in] This governs whether we handle whitespace specially (see WHITESPACE_COMPARE_ALL, WHITESPACE_IGNORE_CHANGE, WHITESPACE_IGNORE_ALL) * @param [out] begin return -1 if not found or pos of equal * @param [out]
| 851 | * Assumes whitespace is never leadbyte or trailbyte! |
| 852 | */ |
| 853 | void |
| 854 | stringdiffs::ComputeByteDiff(const String & str1, const String & str2, |
| 855 | bool casitive, int xwhite, |
| 856 | int begin[2], int end[2], bool equal) |
| 857 | { |
| 858 | // Set to sane values |
| 859 | // Also this way can distinguish if we set begin[0] to -1 for no diff in line |
| 860 | begin[0] = begin[1] = end[0] = end[1] = 0; |
| 861 | |
| 862 | int len1 = static_cast<int>(str1.length()); |
| 863 | int len2 = static_cast<int>(str2.length()); |
| 864 | |
| 865 | const tchar_t *pbeg1 = str1.c_str(); |
| 866 | const tchar_t *pbeg2 = str2.c_str(); |
| 867 | |
| 868 | ICUBreakIterator *pIterCharBegin1 = ICUBreakIterator::getCharacterBreakIterator(reinterpret_cast<const UChar *>(pbeg1), static_cast<int32_t>(len1)); |
| 869 | ICUBreakIterator *pIterCharBegin2 = ICUBreakIterator::getCharacterBreakIterator<2>(reinterpret_cast<const UChar *>(pbeg2), static_cast<int32_t>(len2)); |
| 870 | ICUBreakIterator *pIterCharEnd1 = ICUBreakIterator::getCharacterBreakIterator<3>(reinterpret_cast<const UChar *>(pbeg1), static_cast<int32_t>(len1)); |
| 871 | ICUBreakIterator *pIterCharEnd2 = ICUBreakIterator::getCharacterBreakIterator<4>(reinterpret_cast<const UChar *>(pbeg2), static_cast<int32_t>(len2)); |
| 872 | |
| 873 | if (len1 == 0 || len2 == 0) |
| 874 | { |
| 875 | if (len1 == len2) |
| 876 | { |
| 877 | begin[0] = begin[1] = end[0] = end[1] = -1; |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | end[0] = len1 - 1; |
| 882 | end[1] = len2 - 1; |
| 883 | } |
| 884 | return; |
| 885 | } |
| 886 | |
| 887 | // cursors from front, which we advance to beginning of difference |
| 888 | const tchar_t *py1 = pbeg1; |
| 889 | const tchar_t *py2 = pbeg2; |
| 890 | |
| 891 | // pen1,pen2 point to the last valid character (broken multibyte lead chars don't count) |
| 892 | const tchar_t *pen1 = pbeg1 + (len1 > 0 ? pIterCharEnd1->preceding(len1) : 0); |
| 893 | const tchar_t *pen2 = pbeg2 + (len2 > 0 ? pIterCharEnd2->preceding(len2) : 0); |
| 894 | size_t glyphlenz1 = pbeg1 + len1 - pen1; |
| 895 | size_t glyphlenz2 = pbeg2 + len2 - pen2; |
| 896 | |
| 897 | if (xwhite != WHITESPACE_COMPARE_ALL) |
| 898 | { |
| 899 | // Ignore leading and trailing whitespace |
| 900 | // by advancing py1 and py2 |
| 901 | // and retreating pen1 and pen2 |
| 902 | while (py1 < pen1 && isSafeWhitespace(*py1)) |
| 903 | py1 = pbeg1 + pIterCharBegin1->next(); |
| 904 | while (py2 < pen2 && isSafeWhitespace(*py2)) |
| 905 | py2 = pbeg2 + pIterCharBegin2->next(); |
| 906 | if ((pen1 < pbeg1 + len1 - 1 || pen2 < pbeg2 + len2 -1) |
| 907 | && (pbeg1[len1] != pbeg2[len2])) |
| 908 | { |
| 909 | // mismatched broken multibyte ends |
| 910 | } |
nothing calls this directly
no test coverage detected