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.
---
 ChangeLog               | 14 ++++++++++++++
 lib/propername-lite.c   | 33 +++++++++++++++++++++++++++------
 modules/propername-lite |  2 --
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 59665cbd73..78c4e7ba9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-09-05  Paul Eggert  <[email protected]>
+
+       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  <[email protected]>
 
        quotearg: do not depend on localcharset
diff --git a/lib/propername-lite.c b/lib/propername-lite.c
index e1fc18f5b0..f11c9746d2 100644
--- a/lib/propername-lite.c
+++ b/lib/propername-lite.c
@@ -19,18 +19,39 @@
 /* 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;
 }
diff --git a/modules/propername-lite b/modules/propername-lite
index 617873df63..2b002debb1 100644
--- a/modules/propername-lite
+++ b/modules/propername-lite
@@ -6,8 +6,6 @@ lib/propername-lite.c
 lib/propername.h
 
 Depends-on:
-localcharset
-c-strcasecmp
 gettext-h
 
 configure.ac:
-- 
2.48.1


Reply via email to