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.
This commit is contained in:
Paul Eggert 2023-06-06 13:55:56 -07:00
parent c89fd071d5
commit a2e301b52c
3 changed files with 10 additions and 9 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -22,7 +22,7 @@
#include "diff.h"
#include <wchar.h>
#include <uchar.h>
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)