]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
localeinfo: use countof
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 May 2026 01:11:07 +0000 (18:11 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 May 2026 01:25:11 +0000 (18:25 -0700)
* lib/localeinfo.c: Include stdcountof.h.
Simplify by using countof.
* modules/localeinfo (Depends-on): Add stdcountof-h.

ChangeLog
lib/localeinfo.c
modules/localeinfo

index 692becea0caa2dadfccfc1f0e26ad7a627a564c8..61e588a7365e4df92539fef6e968f2c29a24919a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2026-05-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       localeinfo: use countof
+       * lib/localeinfo.c: Include stdcountof.h.
+       Simplify by using countof.
+       * modules/localeinfo (Depends-on): Add stdcountof-h.
+
        localeinfo: new module
        This is so regex can use localeinfo.[ch].
        * modules/dfa (Files): Remove lib/localeinfo.c, lib/localeinfo.h.
index e9a253f13c0ae11cc278506ad4bd2cf3fddbe697..4e153ffa294b1fb0f75649addf3010302516a1f1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <limits.h>
 #include <locale.h>
+#include <stdcountof.h>
 #include <stdlib.h>
 #include <string.h>
 #include <uchar.h>
@@ -119,10 +120,9 @@ static unsigned short int const lonesome_lower[] =
     0x03F5, 0x1E9B, 0x1FBE,
   };
 
-/* Verify that the worst case fits.  This is 1 for c32toupper, 1 for
+/* Verify that the worst multibyte case fits.  This is 1 for c32toupper, 1 for
    c32tolower, and 1 for each entry in LONESOME_LOWER.  */
-verify (1 + 1 + sizeof lonesome_lower / sizeof *lonesome_lower
-        <= CASE_FOLDED_BUFSIZE);
+verify (1 + 1 + countof (lonesome_lower) <= CASE_FOLDED_BUFSIZE);
 
 /* Find the characters equal to C after case-folding, other than C
    itself, and store them into FOLDED.  Return the number of characters
@@ -138,7 +138,7 @@ case_folded_counterparts (wint_t c, char32_t folded[CASE_FOLDED_BUFSIZE])
     folded[n++] = uc;
   if (lc != uc && lc != c && c32toupper (lc) == uc)
     folded[n++] = lc;
-  for (int i = 0; i < sizeof lonesome_lower / sizeof *lonesome_lower; i++)
+  for (int i = 0; i < countof (lonesome_lower); i++)
     {
       wint_t li = lonesome_lower[i];
       if (li != lc && li != uc && li != c && c32toupper (li) == uc)
index 7981af292c3c8507f9559729f92438954ec75372..2fc871ee10fd5602e080f88c5f642aafe4e1f74b 100644 (file)
@@ -13,6 +13,7 @@ c99
 limits-h
 mbrtoc32-regular
 mbszero
+stdcountof-h
 uchar-h
 # The lonesome_lower array requires ISO C 23 semantics for char32_t.
 # But uchar-h-c23 has a global effect, therefore leave it to each package