#262 ustat() to show the byte length of UTF-8 char (with patch)

open
nobody
5
2008-11-15
2008-11-15
Péter Szabó
No

This patch extends ustat() by showing the number of bytes the current
character occupies. This information is useful for debugging UTF-8 text.

Index: bw.c

--- bw.c (revision 28)
+++ bw.c (working copy)
@@ -1273,8 +1273,15 @@
static unsigned char buf[160];
unsigned char bf1[100];
unsigned char bf2[100];
- int c = brch(bw->cursor);
+ P pbak;
+ int c;
+ int bytelen;

+ pbak = *bw->cursor;
+ c = pgetc(bw->cursor);
+ bytelen = bw->cursor->byte - pbak.byte;
+ *bw->cursor = pbak;
+
#if SIZEOF_LONG_LONG && SIZEOF_LONG_LONG == SIZEOF_OFF_T
joe_snprintf_1(bf1, sizeof(bf1), "%lld", bw->cursor->byte);
joe_snprintf_1(bf2, sizeof(bf2), "%llx", bw->cursor->byte);
@@ -1286,7 +1293,7 @@
if (c == NO_MORE_DATA)
joe_snprintf_4(buf, sizeof(buf), joe_gettext(_("** Line %ld Col %ld Offset %s(0x%s) **")), bw->cursor->line + 1, piscol(bw->cursor) + 1, bf1, bf2);
else
- joe_snprintf_9(buf, sizeof(buf), joe_gettext(_("** Line %ld Col %ld Offset %s(0x%s) %s %d(0%o/0x%X) Width %d **")), bw->cursor->line + 1, piscol(bw->cursor) + 1, bf1, bf2, bw->b->o.charmap->name, c, c, c, joe_wcwidth(bw->o.charmap->type,c));
+ joe_snprintf_10(buf, sizeof(buf), joe_gettext(_("** Line %ld Col %ld Offset %s(0x%s) %s %d(0%o/0x%X) Width %d/%d **")), bw->cursor->line + 1, piscol(bw->cursor) + 1, bf1, bf2, bw->b->o.charmap->name, c, c, c, joe_wcwidth(bw->o.charmap->type,c), bytelen);
msgnw(bw->parent, buf);
return 0;
}

Discussion