Fossil SCM

Additional fixes to side-by-side diff coloration for multibyte UTF8 text.

drh 2013-03-02 18:30 trunk
Commit 85ca387557c92151384a825c4b9d497758ce389c
1 file changed +9 -10
+9 -10
--- src/diff.c
+++ src/diff.c
@@ -858,16 +858,16 @@
858858
** * If iStart is a null-change then move iStart2 into iStart
859859
** * Make sure any null-changes are in canonoical form.
860860
** * Make sure all changes are at character boundaries for
861861
** multi-byte characters.
862862
*/
863
-static void sbsSimplifyLine(SbsLine *p){
863
+static void sbsSimplifyLine(SbsLine *p, const char *z){
864864
if( p->iStart2==p->iEnd2 ){
865865
p->iStart2 = p->iEnd2 = 0;
866866
}else if( p->iStart2 ){
867
- while( p->iStart2>0 && (p->zLine[p->iStart2]&0xc0)==0x80 ) p->iStart2--;
868
- while( (p->zLine[p->iEnd2+1]&0xc0)==0x80 ) p->iEnd2++;
867
+ while( p->iStart2>0 && (z[p->iStart2]&0xc0)==0x80 ) p->iStart2--;
868
+ while( (z[p->iEnd2]&0xc0)==0x80 ) p->iEnd2++;
869869
}
870870
if( p->iStart==p->iEnd ){
871871
p->iStart = p->iStart2;
872872
p->iEnd = p->iEnd2;
873873
p->zStart = p->zStart2;
@@ -875,12 +875,12 @@
875875
p->iEnd2 = 0;
876876
}
877877
if( p->iStart==p->iEnd ){
878878
p->iStart = p->iEnd = -1;
879879
}else if( p->iStart>0 ){
880
- while( p->iStart>0 && (p->zLine[p->iStart]&0xc0)==0x80 ) p->iStart--;
881
- while( (p->zLine[p->iEnd+1]&0xc0)==0x80 ) p->iEnd++;
880
+ while( p->iStart>0 && (z[p->iStart]&0xc0)==0x80 ) p->iStart--;
881
+ while( (z[p->iEnd]&0xc0)==0x80 ) p->iEnd++;
882882
}
883883
}
884884
885885
/*
886886
** Write out lines that have been edited. Adjust the highlight to cover
@@ -920,16 +920,15 @@
920920
if( nPrefix<nShort ){
921921
while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--;
922922
}
923923
nSuffix = 0;
924924
if( nPrefix<nShort ){
925
- while( nSuffix<nShort
926
- && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
925
+ while( nSuffix<nShort && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
927926
nSuffix++;
928927
}
929928
if( nSuffix<nShort ){
930
- while( nSuffix>0 && (zLeft[nLeft-nSuffix+1]&0xc0)==0x80 ) nSuffix--;
929
+ while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
931930
}
932931
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
933932
}
934933
if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
935934
@@ -990,11 +989,11 @@
990989
p->zStart = zClassChng;
991990
}
992991
p->iStart2 = nPrefix + aLCS[1];
993992
p->iEnd2 = nLeft - nSuffix;
994993
p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng;
995
- sbsSimplifyLine(p);
994
+ sbsSimplifyLine(p, zLeft+nPrefix);
996995
sbsWriteText(p, pLeft, SBS_PAD);
997996
sbsWrite(p, " | ", 3);
998997
sbsWriteLineno(p, lnRight);
999998
p->iStart = nPrefix;
1000999
p->iEnd = nPrefix + aLCS[2];
@@ -1005,11 +1004,11 @@
10051004
p->zStart = zClassChng;
10061005
}
10071006
p->iStart2 = nPrefix + aLCS[3];
10081007
p->iEnd2 = nRight - nSuffix;
10091008
p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng;
1010
- sbsSimplifyLine(p);
1009
+ sbsSimplifyLine(p, zRight+nPrefix);
10111010
sbsWriteText(p, pRight, SBS_NEWLINE);
10121011
return;
10131012
}
10141013
10151014
/* If all else fails, show a single big change between left and right */
10161015
--- src/diff.c
+++ src/diff.c
@@ -858,16 +858,16 @@
858 ** * If iStart is a null-change then move iStart2 into iStart
859 ** * Make sure any null-changes are in canonoical form.
860 ** * Make sure all changes are at character boundaries for
861 ** multi-byte characters.
862 */
863 static void sbsSimplifyLine(SbsLine *p){
864 if( p->iStart2==p->iEnd2 ){
865 p->iStart2 = p->iEnd2 = 0;
866 }else if( p->iStart2 ){
867 while( p->iStart2>0 && (p->zLine[p->iStart2]&0xc0)==0x80 ) p->iStart2--;
868 while( (p->zLine[p->iEnd2+1]&0xc0)==0x80 ) p->iEnd2++;
869 }
870 if( p->iStart==p->iEnd ){
871 p->iStart = p->iStart2;
872 p->iEnd = p->iEnd2;
873 p->zStart = p->zStart2;
@@ -875,12 +875,12 @@
875 p->iEnd2 = 0;
876 }
877 if( p->iStart==p->iEnd ){
878 p->iStart = p->iEnd = -1;
879 }else if( p->iStart>0 ){
880 while( p->iStart>0 && (p->zLine[p->iStart]&0xc0)==0x80 ) p->iStart--;
881 while( (p->zLine[p->iEnd+1]&0xc0)==0x80 ) p->iEnd++;
882 }
883 }
884
885 /*
886 ** Write out lines that have been edited. Adjust the highlight to cover
@@ -920,16 +920,15 @@
920 if( nPrefix<nShort ){
921 while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--;
922 }
923 nSuffix = 0;
924 if( nPrefix<nShort ){
925 while( nSuffix<nShort
926 && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
927 nSuffix++;
928 }
929 if( nSuffix<nShort ){
930 while( nSuffix>0 && (zLeft[nLeft-nSuffix+1]&0xc0)==0x80 ) nSuffix--;
931 }
932 if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
933 }
934 if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
935
@@ -990,11 +989,11 @@
990 p->zStart = zClassChng;
991 }
992 p->iStart2 = nPrefix + aLCS[1];
993 p->iEnd2 = nLeft - nSuffix;
994 p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng;
995 sbsSimplifyLine(p);
996 sbsWriteText(p, pLeft, SBS_PAD);
997 sbsWrite(p, " | ", 3);
998 sbsWriteLineno(p, lnRight);
999 p->iStart = nPrefix;
1000 p->iEnd = nPrefix + aLCS[2];
@@ -1005,11 +1004,11 @@
1005 p->zStart = zClassChng;
1006 }
1007 p->iStart2 = nPrefix + aLCS[3];
1008 p->iEnd2 = nRight - nSuffix;
1009 p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng;
1010 sbsSimplifyLine(p);
1011 sbsWriteText(p, pRight, SBS_NEWLINE);
1012 return;
1013 }
1014
1015 /* If all else fails, show a single big change between left and right */
1016
--- src/diff.c
+++ src/diff.c
@@ -858,16 +858,16 @@
858 ** * If iStart is a null-change then move iStart2 into iStart
859 ** * Make sure any null-changes are in canonoical form.
860 ** * Make sure all changes are at character boundaries for
861 ** multi-byte characters.
862 */
863 static void sbsSimplifyLine(SbsLine *p, const char *z){
864 if( p->iStart2==p->iEnd2 ){
865 p->iStart2 = p->iEnd2 = 0;
866 }else if( p->iStart2 ){
867 while( p->iStart2>0 && (z[p->iStart2]&0xc0)==0x80 ) p->iStart2--;
868 while( (z[p->iEnd2]&0xc0)==0x80 ) p->iEnd2++;
869 }
870 if( p->iStart==p->iEnd ){
871 p->iStart = p->iStart2;
872 p->iEnd = p->iEnd2;
873 p->zStart = p->zStart2;
@@ -875,12 +875,12 @@
875 p->iEnd2 = 0;
876 }
877 if( p->iStart==p->iEnd ){
878 p->iStart = p->iEnd = -1;
879 }else if( p->iStart>0 ){
880 while( p->iStart>0 && (z[p->iStart]&0xc0)==0x80 ) p->iStart--;
881 while( (z[p->iEnd]&0xc0)==0x80 ) p->iEnd++;
882 }
883 }
884
885 /*
886 ** Write out lines that have been edited. Adjust the highlight to cover
@@ -920,16 +920,15 @@
920 if( nPrefix<nShort ){
921 while( nPrefix>0 && (zLeft[nPrefix]&0xc0)==0x80 ) nPrefix--;
922 }
923 nSuffix = 0;
924 if( nPrefix<nShort ){
925 while( nSuffix<nShort && zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
 
926 nSuffix++;
927 }
928 if( nSuffix<nShort ){
929 while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
930 }
931 if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
932 }
933 if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
934
@@ -990,11 +989,11 @@
989 p->zStart = zClassChng;
990 }
991 p->iStart2 = nPrefix + aLCS[1];
992 p->iEnd2 = nLeft - nSuffix;
993 p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng;
994 sbsSimplifyLine(p, zLeft+nPrefix);
995 sbsWriteText(p, pLeft, SBS_PAD);
996 sbsWrite(p, " | ", 3);
997 sbsWriteLineno(p, lnRight);
998 p->iStart = nPrefix;
999 p->iEnd = nPrefix + aLCS[2];
@@ -1005,11 +1004,11 @@
1004 p->zStart = zClassChng;
1005 }
1006 p->iStart2 = nPrefix + aLCS[3];
1007 p->iEnd2 = nRight - nSuffix;
1008 p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng;
1009 sbsSimplifyLine(p, zRight+nPrefix);
1010 sbsWriteText(p, pRight, SBS_NEWLINE);
1011 return;
1012 }
1013
1014 /* If all else fails, show a single big change between left and right */
1015

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button