comparison src/diff.c @ 15595:1ec942f1b648 v8.1.0805

patch 8.1.0805: too many #ifdefs commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 24 15:04:48 2019 +0100 patch 8.1.0805: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate FEAT_MBYTE, part 1.
author Bram Moolenaar <Bram@vim.org>
date Thu, 24 Jan 2019 15:15:06 +0100
parents 98c35d312987
children 734b1928a5aa
comparison
equal deleted inserted replaced
15594:7a8983fe4f97 15595:1ec942f1b648
739 for (s = ml_get_buf(buf, lnum, FALSE); *s != NUL; ) 739 for (s = ml_get_buf(buf, lnum, FALSE); *s != NUL; )
740 { 740 {
741 if (diff_flags & DIFF_ICASE) 741 if (diff_flags & DIFF_ICASE)
742 { 742 {
743 int c; 743 int c;
744
745 // xdiff doesn't support ignoring case, fold-case the text.
746 #ifdef FEAT_MBYTE
747 int orig_len; 744 int orig_len;
748 char_u cbuf[MB_MAXBYTES + 1]; 745 char_u cbuf[MB_MAXBYTES + 1];
749 746
747 // xdiff doesn't support ignoring case, fold-case the text.
750 c = PTR2CHAR(s); 748 c = PTR2CHAR(s);
751 c = enc_utf8 ? utf_fold(c) : MB_TOLOWER(c); 749 c = enc_utf8 ? utf_fold(c) : MB_TOLOWER(c);
752 orig_len = MB_PTR2LEN(s); 750 orig_len = MB_PTR2LEN(s);
753 if (mb_char2bytes(c, cbuf) != orig_len) 751 if (mb_char2bytes(c, cbuf) != orig_len)
754 // TODO: handle byte length difference 752 // TODO: handle byte length difference
756 else 754 else
757 mch_memmove(ptr + len, cbuf, orig_len); 755 mch_memmove(ptr + len, cbuf, orig_len);
758 756
759 s += orig_len; 757 s += orig_len;
760 len += orig_len; 758 len += orig_len;
761 #else
762 c = *s++;
763 ptr[len++] = TOLOWER_LOC(c);
764 #endif
765 } 759 }
766 else 760 else
767 ptr[len++] = *s++; 761 ptr[len++] = *s++;
768 } 762 }
769 ptr[len++] = NL; 763 ptr[len++] = NL;
1944 * ignoring case) return TRUE and set "len" to the number of bytes. 1938 * ignoring case) return TRUE and set "len" to the number of bytes.
1945 */ 1939 */
1946 static int 1940 static int
1947 diff_equal_char(char_u *p1, char_u *p2, int *len) 1941 diff_equal_char(char_u *p1, char_u *p2, int *len)
1948 { 1942 {
1949 #ifdef FEAT_MBYTE
1950 int l = (*mb_ptr2len)(p1); 1943 int l = (*mb_ptr2len)(p1);
1951 1944
1952 if (l != (*mb_ptr2len)(p2)) 1945 if (l != (*mb_ptr2len)(p2))
1953 return FALSE; 1946 return FALSE;
1954 if (l > 1) 1947 if (l > 1)
1960 != utf_fold(utf_ptr2char(p2)))) 1953 != utf_fold(utf_ptr2char(p2))))
1961 return FALSE; 1954 return FALSE;
1962 *len = l; 1955 *len = l;
1963 } 1956 }
1964 else 1957 else
1965 #endif
1966 { 1958 {
1967 if ((*p1 != *p2) 1959 if ((*p1 != *p2)
1968 && (!(diff_flags & DIFF_ICASE) 1960 && (!(diff_flags & DIFF_ICASE)
1969 || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2))) 1961 || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))
1970 return FALSE; 1962 return FALSE;
2398 break; 2390 break;
2399 si_org += l; 2391 si_org += l;
2400 si_new += l; 2392 si_new += l;
2401 } 2393 }
2402 } 2394 }
2403 #ifdef FEAT_MBYTE
2404 if (has_mbyte) 2395 if (has_mbyte)
2405 { 2396 {
2406 /* Move back to first byte of character in both lines (may 2397 /* Move back to first byte of character in both lines (may
2407 * have "nn^" in line_org and "n^ in line_new). */ 2398 * have "nn^" in line_org and "n^ in line_new). */
2408 si_org -= (*mb_head_off)(line_org, line_org + si_org); 2399 si_org -= (*mb_head_off)(line_org, line_org + si_org);
2409 si_new -= (*mb_head_off)(line_new, line_new + si_new); 2400 si_new -= (*mb_head_off)(line_new, line_new + si_new);
2410 } 2401 }
2411 #endif
2412 if (*startp > si_org) 2402 if (*startp > si_org)
2413 *startp = si_org; 2403 *startp = si_org;
2414 2404
2415 /* Search for end of difference, if any. */ 2405 /* Search for end of difference, if any. */
2416 if (line_org[si_org] != NUL || line_new[si_new] != NUL) 2406 if (line_org[si_org] != NUL || line_new[si_new] != NUL)
2436 } 2426 }
2437 else 2427 else
2438 { 2428 {
2439 p1 = line_org + ei_org; 2429 p1 = line_org + ei_org;
2440 p2 = line_new + ei_new; 2430 p2 = line_new + ei_new;
2441 #ifdef FEAT_MBYTE
2442 p1 -= (*mb_head_off)(line_org, p1); 2431 p1 -= (*mb_head_off)(line_org, p1);
2443 p2 -= (*mb_head_off)(line_new, p2); 2432 p2 -= (*mb_head_off)(line_new, p2);
2444 #endif
2445 if (!diff_equal_char(p1, p2, &l)) 2433 if (!diff_equal_char(p1, p2, &l))
2446 break; 2434 break;
2447 ei_org -= l; 2435 ei_org -= l;
2448 ei_new -= l; 2436 ei_new -= l;
2449 } 2437 }