From a2e301b52cc5bdb44540aa66860dc59fa1fa5a89 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 6 Jun 2023 13:55:56 -0700 Subject: [PATCH] diff: switch from wchar_t to char32_t Prefer C11-style char32_t to wchar_t, as char32_t works better on platforms where wchar_t is only 16 bits. * .gitignore: Add lib/uchar.h. * bootstrap.conf (gnulib_modules): Add c32width, mbrtoc32. Remove mbrtowc. Sort. * src/side.c: Include uchar.h instead of wchar.h. (print_half_line): Use c32width and mbrtowc instead of wcwidth and mbrtowc. --- .gitignore | 1 + bootstrap.conf | 10 +++++----- src/side.c | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9c28f11..0ee17cf 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,7 @@ lib/uniwidth.h lib/warn-on-use.h lib/wchar.h lib/wctype.h +lib/uchar.h man/*.1 po/*.gmo po/*.po diff --git a/bootstrap.conf b/bootstrap.conf index 2560846..4b3f02d 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -24,11 +24,11 @@ avoided_gnulib_modules=' # gnulib modules used by this package. gnulib_modules=' announce-gen -attribute argmatch +attribute binary-io -nullptr c-stack +c32width config-h count-leading-zeros diffseq @@ -40,10 +40,10 @@ exclude exitfail extensions extern-inline -flexmember fcntl file-type filenamecat +flexmember fnmatch-gnu getopt-gnu gettext-h @@ -65,12 +65,13 @@ largefile lstat maintainer-makefile manywarnings -mbrtowc +mbrtoc32 mempcpy minmax mkstemp mktime nstrftime +nullptr perl progname propername-lite @@ -101,7 +102,6 @@ update-copyright verify version-etc version-etc-fsf -wcwidth xalloc xfreopen xmalloca diff --git a/src/side.c b/src/side.c index c4042dd..424d933 100644 --- a/src/side.c +++ b/src/side.c @@ -22,7 +22,7 @@ #include "diff.h" -#include +#include static void print_sdiff_common_lines (lin, lin); static void print_sdiff_hunk (struct change *); @@ -135,12 +135,12 @@ print_half_line (char const *const *line, intmax_t indent, intmax_t out_bound) default: { - wchar_t wc; - size_t bytes = mbrtowc (&wc, tp0, text_limit - tp0, &mbstate); + char32_t wc; + size_t bytes = mbrtoc32 (&wc, tp0, text_limit - tp0, &mbstate); if (0 < bytes && bytes < (size_t) -2) { - int width = wcwidth (wc); + int width = c32width (wc); if (0 < width) in_position += width; if (in_position <= out_bound)