Fossil SCM

Fix --debug diff output for multi-byte UTF-8.

drh 2021-08-30 14:23 diff-color-enhancements
Commit 9191ea9e63d1697dab52eb79efd79f4b452f7c14985f78e0315f7f75bd626f34
1 file changed +18 -6
+18 -6
--- src/diff.c
+++ src/diff.c
@@ -727,13 +727,15 @@
727727
int i, j, k; /* Loop counters */
728728
int lenBest = 0; /* Match length to beat */
729729
730730
for(i=0; i<nA-lenBest; i++){
731731
unsigned char cA = zA[i];
732
+ if( (cA&0xc0)==0x80 ) continue;
732733
for(j=0; j<nB-lenBest; j++ ){
733734
if( zB[j]==cA ){
734735
for(k=1; j+k<nB && i+k<nA && zB[j+k]==zA[i+k]; k++){}
736
+ while( (zB[j+k]&0xc0)==0x80 ){ k--; }
735737
if( k>lenBest ){
736738
lenBest = k;
737739
aLCS[0] = i;
738740
aLCS[1] = i+k;
739741
aLCS[2] = j;
@@ -1671,25 +1673,35 @@
16711673
oneLineChange(pX, pY, &span);
16721674
for(i=x=0; i<span.n; i++){
16731675
int ofst = span.a[i].iStart1;
16741676
int len = span.a[i].iLen1;
16751677
if( len ){
1676
- blob_appendf(p->pOut, "%*s", ofst+25 - x, "");
1677
- for(j=0; j<len; j++) blob_append_char(p->pOut, '^');
1678
- x = ofst+len+25;
1678
+ if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
1679
+ while( ofst > x ){
1680
+ if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
1681
+ x++;
1682
+ }
1683
+ for(j=0; j<len; j++, x++){
1684
+ if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
1685
+ }
16791686
}
16801687
}
16811688
if( x ) blob_append_char(p->pOut, '\n');
16821689
blob_appendf(p->pOut, " %8u %.*s\n",
16831690
p->lnRight, (int)pY->n, pY->z);
16841691
for(i=x=0; i<span.n; i++){
16851692
int ofst = span.a[i].iStart2;
16861693
int len = span.a[i].iLen2;
16871694
if( len ){
1688
- blob_appendf(p->pOut, "%*s", ofst+25 - x, "");
1689
- for(j=0; j<len; j++) blob_append_char(p->pOut, '^');
1690
- x = ofst+len+25;
1695
+ if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
1696
+ while( ofst > x ){
1697
+ if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
1698
+ x++;
1699
+ }
1700
+ for(j=0; j<len; j++, x++){
1701
+ if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
1702
+ }
16911703
}
16921704
}
16931705
if( x ) blob_append_char(p->pOut, '\n');
16941706
}
16951707
static void dfdebugEnd(DiffBuilder *p){
16961708
--- src/diff.c
+++ src/diff.c
@@ -727,13 +727,15 @@
727 int i, j, k; /* Loop counters */
728 int lenBest = 0; /* Match length to beat */
729
730 for(i=0; i<nA-lenBest; i++){
731 unsigned char cA = zA[i];
 
732 for(j=0; j<nB-lenBest; j++ ){
733 if( zB[j]==cA ){
734 for(k=1; j+k<nB && i+k<nA && zB[j+k]==zA[i+k]; k++){}
 
735 if( k>lenBest ){
736 lenBest = k;
737 aLCS[0] = i;
738 aLCS[1] = i+k;
739 aLCS[2] = j;
@@ -1671,25 +1673,35 @@
1671 oneLineChange(pX, pY, &span);
1672 for(i=x=0; i<span.n; i++){
1673 int ofst = span.a[i].iStart1;
1674 int len = span.a[i].iLen1;
1675 if( len ){
1676 blob_appendf(p->pOut, "%*s", ofst+25 - x, "");
1677 for(j=0; j<len; j++) blob_append_char(p->pOut, '^');
1678 x = ofst+len+25;
 
 
 
 
 
1679 }
1680 }
1681 if( x ) blob_append_char(p->pOut, '\n');
1682 blob_appendf(p->pOut, " %8u %.*s\n",
1683 p->lnRight, (int)pY->n, pY->z);
1684 for(i=x=0; i<span.n; i++){
1685 int ofst = span.a[i].iStart2;
1686 int len = span.a[i].iLen2;
1687 if( len ){
1688 blob_appendf(p->pOut, "%*s", ofst+25 - x, "");
1689 for(j=0; j<len; j++) blob_append_char(p->pOut, '^');
1690 x = ofst+len+25;
 
 
 
 
 
1691 }
1692 }
1693 if( x ) blob_append_char(p->pOut, '\n');
1694 }
1695 static void dfdebugEnd(DiffBuilder *p){
1696
--- src/diff.c
+++ src/diff.c
@@ -727,13 +727,15 @@
727 int i, j, k; /* Loop counters */
728 int lenBest = 0; /* Match length to beat */
729
730 for(i=0; i<nA-lenBest; i++){
731 unsigned char cA = zA[i];
732 if( (cA&0xc0)==0x80 ) continue;
733 for(j=0; j<nB-lenBest; j++ ){
734 if( zB[j]==cA ){
735 for(k=1; j+k<nB && i+k<nA && zB[j+k]==zA[i+k]; k++){}
736 while( (zB[j+k]&0xc0)==0x80 ){ k--; }
737 if( k>lenBest ){
738 lenBest = k;
739 aLCS[0] = i;
740 aLCS[1] = i+k;
741 aLCS[2] = j;
@@ -1671,25 +1673,35 @@
1673 oneLineChange(pX, pY, &span);
1674 for(i=x=0; i<span.n; i++){
1675 int ofst = span.a[i].iStart1;
1676 int len = span.a[i].iLen1;
1677 if( len ){
1678 if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
1679 while( ofst > x ){
1680 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
1681 x++;
1682 }
1683 for(j=0; j<len; j++, x++){
1684 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
1685 }
1686 }
1687 }
1688 if( x ) blob_append_char(p->pOut, '\n');
1689 blob_appendf(p->pOut, " %8u %.*s\n",
1690 p->lnRight, (int)pY->n, pY->z);
1691 for(i=x=0; i<span.n; i++){
1692 int ofst = span.a[i].iStart2;
1693 int len = span.a[i].iLen2;
1694 if( len ){
1695 if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
1696 while( ofst > x ){
1697 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
1698 x++;
1699 }
1700 for(j=0; j<len; j++, x++){
1701 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
1702 }
1703 }
1704 }
1705 if( x ) blob_append_char(p->pOut, '\n');
1706 }
1707 static void dfdebugEnd(DiffBuilder *p){
1708

Keyboard Shortcuts

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