>From 495807631133641cc0d08d03afd4219c4c413dde Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 3 Oct 2026 20:46:08 -0400 Subject: [PATCH 06/10] locale: provide access to numeric grouping rules --- src/locale/locale_map.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c index 2e459931..7b1f090f 100644 --- a/src/locale/locale_map.c +++ b/src/locale/locale_map.c @@ -45,6 +45,25 @@ int __radixpt(locale_t loc) return '.' - loc->cat[LC_NUMERIC]->alt_radix; } +const char *__get_grouping(const char **psep, size_t *pseplen) +{ + locale_t loc = CURRENT_LOCALE; + const unsigned char *root = LMEMB(loc, LC_NUMERIC, table_root); + const unsigned char *lconv = ikmlt_lookup(root, K_LCONV); + const char *grouping = ikmlt_lookup(lconv, 2); + const char *sep = ikmlt_lookup(lconv, 1); + size_t l; + if (!grouping || !sep || (l=strlen(sep)) > MB_LEN_MAX) { + static const char no_grouping[] = { CHAR_MAX, 0 }; + *pseplen = 0; + *psep = 0; + return no_grouping; + } + *pseplen = l; + *psep = sep; + return grouping; +} + static int load_locale(struct __locale_map *l, const unsigned char *lm) { const unsigned char *root; -- 2.21.0