1/* Iterator for grouping a number while scanning it forward.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef GROUPING_ITERATOR_H
20#define GROUPING_ITERATOR_H
21
22#include <locale.h>
23#include <stdbool.h>
24
25struct grouping_iterator
26{
27 /* Number of characters in the current group. If this reaches zero,
28 a thousands separator needs to be emittted. */
29 unsigned int remaining_in_current_group;
30
31 /* Number of characters remaining in the number. This is used to
32 detect the start of the non-repeating groups. */
33 unsigned int remaining;
34
35 /* Points to the current grouping descriptor. */
36 const char *groupings;
37
38 /* Total number of characters in the non-repeating groups. */
39 unsigned int non_repeating_groups;
40
41 /* Number of separators that will be inserted if the whole number is
42 processed. (Does not change during iteration.) */
43 unsigned int separators;
44};
45
46struct __locale_data;
47
48/* Initializes *IT with the data from LOCDATA (which must be for
49 LC_MONETARY or LC_NUMERIC). DIGITS is the length of the number.
50 Returns true if grouping is active, false if not. */
51bool __grouping_iterator_init (struct grouping_iterator *it,
52 int category, locale_t loc,
53 unsigned int digits) attribute_hidden;
54
55/* Initializes *IT with no grouping information for a string of length
56 DIGITS, and return false to indicate no grouping. */
57bool __grouping_iterator_init_none (struct grouping_iterator *it,
58 unsigned int digits)
59 attribute_hidden;
60
61/* Advances to the next character and returns true if a thousands
62 separator should be inserted before emitting it. */
63bool __grouping_iterator_next (struct grouping_iterator *it);
64
65#endif /* GROUPING_ITERATOR_H */
66

source code of glibc/stdio-common/grouping_iterator.h