@@ -1949,6 +1949,40 @@ diffopt_horizontal(void)
19491949 return (diff_flags & DIFF_HORIZONTAL ) != 0 ;
19501950}
19511951
1952+ /*
1953+ * Compare the characters at "p1" and "p2". If they are equal (possibly
1954+ * ignoring case) return TRUE and set "len" to the number of bytes.
1955+ */
1956+ static int
1957+ diff_equal_char (char_u * p1 , char_u * p2 , int * len )
1958+ {
1959+ #ifdef FEAT_MBYTE
1960+ int l = (* mb_ptr2len )(p1 );
1961+
1962+ if (l != (* mb_ptr2len )(p2 ))
1963+ return FALSE;
1964+ if (l > 1 )
1965+ {
1966+ if (STRNCMP (p1 , p2 , l ) != 0
1967+ && (!enc_utf8
1968+ || !(diff_flags & DIFF_ICASE )
1969+ || utf_fold (utf_ptr2char (p1 ))
1970+ != utf_fold (utf_ptr2char (p2 ))))
1971+ return FALSE;
1972+ * len = l ;
1973+ }
1974+ else
1975+ #endif
1976+ {
1977+ if ((* p1 != * p2 )
1978+ && (!(diff_flags & DIFF_ICASE )
1979+ || TOLOWER_LOC (* p1 ) != TOLOWER_LOC (* p2 )))
1980+ return FALSE;
1981+ * len = 1 ;
1982+ }
1983+ return TRUE;
1984+ }
1985+
19521986/*
19531987 * Find the difference within a changed line.
19541988 * Returns TRUE if the line was added, no other buffer has it.
@@ -1969,6 +2003,10 @@ diff_find_change(
19692003 int idx ;
19702004 int off ;
19712005 int added = TRUE;
2006+ #ifdef FEAT_MBYTE
2007+ char_u * p1 , * p2 ;
2008+ int l ;
2009+ #endif
19722010
19732011 /* Make a copy of the line, the next ml_get() will invalidate it. */
19742012 line_org = vim_strsave (ml_get_buf (wp -> w_buffer , lnum , FALSE));
@@ -2017,10 +2055,11 @@ diff_find_change(
20172055 }
20182056 else
20192057 {
2020- if (line_org [si_org ] != line_new [si_new ])
2058+ if (!diff_equal_char (line_org + si_org , line_new + si_new ,
2059+ & l ))
20212060 break ;
2022- ++ si_org ;
2023- ++ si_new ;
2061+ si_org += l ;
2062+ si_new += l ;
20242063 }
20252064 }
20262065#ifdef FEAT_MBYTE
@@ -2056,10 +2095,16 @@ diff_find_change(
20562095 }
20572096 else
20582097 {
2059- if (line_org [ei_org ] != line_new [ei_new ])
2098+ p1 = line_org + ei_org ;
2099+ p2 = line_new + ei_new ;
2100+ #ifdef FEAT_MBYTE
2101+ p1 -= (* mb_head_off )(line_org , p1 );
2102+ p2 -= (* mb_head_off )(line_new , p2 );
2103+ #endif
2104+ if (!diff_equal_char (p1 , p2 , & l ))
20602105 break ;
2061- -- ei_org ;
2062- -- ei_new ;
2106+ ei_org -= l ;
2107+ ei_new -= l ;
20632108 }
20642109 }
20652110 if (* endp < ei_org )
0 commit comments