Fossil SCM

Account for multibyte unicode characters when computing column widths for side-by-side diffs.

drh 2012-06-20 11:02 trunk
Commit 484f8d29af0d130e5b5bb62eb69285a1c83cbd96
1 file changed +3 -2
+3 -2
--- src/diff.c
+++ src/diff.c
@@ -379,11 +379,11 @@
379379
/*
380380
** Write up to width characters of pLine into p->zLine[]. Translate tabs into
381381
** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
382382
** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
383383
**
384
-** This comment contains multi-byte unicode characters (ü, Æ, ð) in order
384
+** This comment contains multibyte unicode characters (ü, Æ, ð) in order
385385
** to test the ability of the diff code to handle such characters.
386386
*/
387387
static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
388388
int n = pLine->h & LENGTH_MASK;
389389
int i; /* Number of input characters consumed */
@@ -430,10 +430,11 @@
430430
}else if( c=='>' && p->escHtml ){
431431
memcpy(&z[j], ">", 4);
432432
j += 4;
433433
}else{
434434
z[j++] = c;
435
+ if( (c&0xc0)==0x80 ) k--;
435436
}
436437
}
437438
if( needEndSpan ){
438439
memcpy(&z[j], "</span>", 7);
439440
j += 7;
@@ -885,11 +886,11 @@
885886
int skip; /* Number of lines to skip */
886887
int nChunk = 0; /* Number of chunks of diff output seen so far */
887888
SbsLine s; /* Output line buffer */
888889
889890
memset(&s, 0, sizeof(s));
890
- s.zLine = fossil_malloc( 10*width + 200 );
891
+ s.zLine = fossil_malloc( 15*width + 200 );
891892
if( s.zLine==0 ) return;
892893
s.width = width;
893894
s.escHtml = escHtml;
894895
s.iStart = -1;
895896
s.iStart2 = 0;
896897
--- src/diff.c
+++ src/diff.c
@@ -379,11 +379,11 @@
379 /*
380 ** Write up to width characters of pLine into p->zLine[]. Translate tabs into
381 ** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
382 ** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
383 **
384 ** This comment contains multi-byte unicode characters (ü, Æ, ð) in order
385 ** to test the ability of the diff code to handle such characters.
386 */
387 static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
388 int n = pLine->h & LENGTH_MASK;
389 int i; /* Number of input characters consumed */
@@ -430,10 +430,11 @@
430 }else if( c=='>' && p->escHtml ){
431 memcpy(&z[j], "&gt;", 4);
432 j += 4;
433 }else{
434 z[j++] = c;
 
435 }
436 }
437 if( needEndSpan ){
438 memcpy(&z[j], "</span>", 7);
439 j += 7;
@@ -885,11 +886,11 @@
885 int skip; /* Number of lines to skip */
886 int nChunk = 0; /* Number of chunks of diff output seen so far */
887 SbsLine s; /* Output line buffer */
888
889 memset(&s, 0, sizeof(s));
890 s.zLine = fossil_malloc( 10*width + 200 );
891 if( s.zLine==0 ) return;
892 s.width = width;
893 s.escHtml = escHtml;
894 s.iStart = -1;
895 s.iStart2 = 0;
896
--- src/diff.c
+++ src/diff.c
@@ -379,11 +379,11 @@
379 /*
380 ** Write up to width characters of pLine into p->zLine[]. Translate tabs into
381 ** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
382 ** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
383 **
384 ** This comment contains multibyte unicode characters (ü, Æ, ð) in order
385 ** to test the ability of the diff code to handle such characters.
386 */
387 static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
388 int n = pLine->h & LENGTH_MASK;
389 int i; /* Number of input characters consumed */
@@ -430,10 +430,11 @@
430 }else if( c=='>' && p->escHtml ){
431 memcpy(&z[j], "&gt;", 4);
432 j += 4;
433 }else{
434 z[j++] = c;
435 if( (c&0xc0)==0x80 ) k--;
436 }
437 }
438 if( needEndSpan ){
439 memcpy(&z[j], "</span>", 7);
440 j += 7;
@@ -885,11 +886,11 @@
886 int skip; /* Number of lines to skip */
887 int nChunk = 0; /* Number of chunks of diff output seen so far */
888 SbsLine s; /* Output line buffer */
889
890 memset(&s, 0, sizeof(s));
891 s.zLine = fossil_malloc( 15*width + 200 );
892 if( s.zLine==0 ) return;
893 s.width = width;
894 s.escHtml = escHtml;
895 s.iStart = -1;
896 s.iStart2 = 0;
897

Keyboard Shortcuts

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