+/* Returns the maximum number of decimal digits in an unsigned
+ binary number that is BYTES bytes long. */
+static int
+max_digits_for_bytes (int bytes)
+{
+ int map[8] = {3, 5, 8, 10, 13, 15, 17, 20};
+ assert (bytes > 0 && bytes <= sizeof map / sizeof *map);
+ return map[bytes - 1];
+}
+\f
+
+/* Creates and returns a new struct fmt_number_style,
+ initializing all affixes to empty strings. */
+struct fmt_number_style *
+fmt_number_style_create (void)
+{
+ struct fmt_number_style *style = xmalloc (sizeof *style);
+ style->neg_prefix = ss_empty ();
+ style->prefix = ss_empty ();
+ style->suffix = ss_empty ();
+ style->neg_suffix = ss_empty ();
+ style->decimal = '.';
+ style->grouping = 0;
+ return style;
+}
+
+/* Destroys a struct fmt_number_style. */
+void
+fmt_number_style_destroy (struct fmt_number_style *style)
+{
+ if (style != NULL)
+ {
+ ss_dealloc (&style->neg_prefix);
+ ss_dealloc (&style->prefix);
+ ss_dealloc (&style->suffix);
+ ss_dealloc (&style->neg_suffix);
+ free (style);
+ }
+}
+
+/* Returns the number formatting style associated with the given
+ format TYPE. */
+const struct fmt_number_style *
+fmt_get_style (enum fmt_type type)
+{
+ assert (is_fmt_type (type));
+ assert (styles[type] != NULL);
+ return styles[type];
+}
+
+/* Sets STYLE as the number formatting style associated with the
+ given format TYPE, transferring ownership of STYLE. */
+void
+fmt_set_style (enum fmt_type type, struct fmt_number_style *style)
+{
+ assert (ss_length (style->neg_prefix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->prefix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->suffix) <= FMT_STYLE_AFFIX_MAX);
+ assert (ss_length (style->neg_suffix) <= FMT_STYLE_AFFIX_MAX);
+ assert (style->decimal == '.' || style->decimal == ',');
+ assert (style->grouping != style->decimal
+ && (style->grouping == '.' || style->grouping == ','
+ || style->grouping == 0));
+
+ assert (fmt_get_category (type) == FMT_CAT_CUSTOM);
+ assert (styles[type] != NULL);
+
+ fmt_number_style_destroy (styles[type]);
+ styles[type] = style;
+}
+
+/* Returns the total width of the standard prefix and suffix for
+ STYLE. */