* lib/localeinfo.c: Include stdcountof.h. Simplify by using countof. * modules/localeinfo (Depends-on): Add stdcountof-h. --- ChangeLog | 5 +++++ lib/localeinfo.c | 8 ++++---- modules/localeinfo | 1 + 3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 692becea0c..61e588a736 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2026-05-05 Paul Eggert <[email protected]> + 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. diff --git a/lib/localeinfo.c b/lib/localeinfo.c index e9a253f13c..4e153ffa29 100644 --- a/lib/localeinfo.c +++ b/lib/localeinfo.c @@ -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) diff --git a/modules/localeinfo b/modules/localeinfo index 7981af292c..2fc871ee10 100644 --- a/modules/localeinfo +++ b/modules/localeinfo @@ -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 -- 2.54.0
