+2025-09-05 Paul Eggert <eggert@cs.ucla.edu>
+
+ propername-lite: lighten it up some more
+ This should help GNU diffutils avoid some Gnulib modules.
+ * lib/propername-lite.c: Do not include c-strcase.h, localcharset.h.
+ Include <uchar.h> and mbrtowc32 if available.
+ Use __has_include to detect this; that should be good enough nowadays.
+ Use native mbrtoc32 instead of Gnulib replacement; that should
+ be good enough. 2nd arg is now possibly unused.
+ Use mbrtoc32, if available, to determine whether UTF-8 is being used,
+ to avoid dependencies.
+ * modules/propername-lite (Depends-on):
+ Remove localcharset, c-strcasecmp.
+
2025-09-04 Paul Eggert <eggert@cs.ucla.edu>
quotearg: do not depend on localcharset
/* Specification. */
#include "propername.h"
-#include "c-strcase.h"
#include "gettext.h"
-#include "localcharset.h"
+
+#ifdef __has_include
+# if __has_include (<uchar.h>)
+# include <uchar.h>
+/* There is no need for the dependency hassle of replacing glibc mbrtoc32,
+ as we don't care whether the C locale treats a byte with the high
+ bit set as an encoding error. */
+# ifdef __GLIBC__
+# undef mbrtoc32
+# endif
+# define USE_MBRTOC32
+# endif
+#endif
/* Return the localization of the name spelled NAME_ASCII in ASCII,
and NAME_UTF8 in UTF-8. */
char const *
-proper_name_lite (char const *name_ascii, char const *name_utf8)
+proper_name_lite (char const *name_ascii, _GL_UNUSED char const *name_utf8)
{
char const *translation = gettext (name_ascii);
- return (translation != name_ascii ? translation
- : c_strcasecmp (locale_charset (), "UTF-8") == 0 ? name_utf8
- : name_ascii);
+ if (translation != name_ascii)
+ return translation;
+
+#ifdef USE_MBRTOC32
+ /* If DF BF decodes to 07FF, assume it is UTF-8. */
+ static char const utf07FF[2] = { 0xDF, 0xBF };
+ char32_t w;
+ mbstate_t mbstate = {0,};
+ if (mbrtoc32 (&w, utf07FF, 2, &mbstate) == 2 && w == 0x07FF)
+ return name_utf8;
+#endif
+
+ return name_ascii;
}