commit 70e3545308c95e2a8ee1a15071c2003b2626bfb1
parent 645bfa79fc6a2855a0e362cd14cc9a1d1d84df56
Author: Chris Bracken <chris@bracken.jp>
Date: Fri, 20 Feb 2026 21:14:48 +0900
format: extract is_unicode_modifier() and kUtf8Ellipsis const
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/format.c b/src/format.c
@@ -7,6 +7,12 @@
#include <time.h>
#include <wchar.h>
+static const char* kUtf8Ellipsis = "\xE2\x80\xA6";
+
+static bool is_unicode_modifier(wchar_t wc) {
+ return wc == 0x200D || (wc >= 0xFE00 && wc <= 0xFE0F);
+}
+
void print_time(FILE* out, time_t time, int timezone_offset) {
assert(out != NULL);
// Reject any offset > 24 hours.
@@ -219,7 +225,7 @@ void print_gopher_link_padded(FILE* out,
if (bytes == (size_t)-1 || bytes == (size_t)-2) {
// Invalid (-1) or incomplete (-2) UTF-8. Consume 1 byte.
if (display_width == width - 1 && ptr + 1 < end) {
- fprintf(out, "\xE2\x80\xA6");
+ fprintf(out, "%s", kUtf8Ellipsis);
display_width++;
break;
} else if (display_width < width) {
@@ -237,7 +243,7 @@ void print_gopher_link_padded(FILE* out,
// Print ellipsis if one character from max width but more remains.
if (display_width == width - 1 && ptr + bytes < end) {
- fprintf(out, "\xE2\x80\xA6");
+ fprintf(out, "%s", kUtf8Ellipsis);
display_width++;
break;
}
@@ -263,7 +269,7 @@ void print_gopher_link_padded(FILE* out,
} else {
// Hack: handle zero-width joiner and variation selector.
// wcwidth lacks awareness of complex emoji modifier sequences.
- if (wc == 0x200D || (wc >= 0xFE00 && wc <= 0xFE0F)) {
+ if (is_unicode_modifier(wc)) {
display_width -= last_char_width;
char_width = 0;
}