-
Notifications
You must be signed in to change notification settings - Fork 12
ST::format_spec
#include <string_theory/formatter>
Name | Summary |
---|---|
alignment_t | Alignment types for filling width |
digit_class_t | Digit classification type |
float_class_t | Floating point classification type |
Name | Summary |
---|---|
(constructor) | Default constructor |
Name | Summary |
---|---|
minimum_length | Minimum width for formatted output |
precision | Number of digits of precision for numeric formats |
arg_index | Index of the argument to format |
alignment | Formatted alignment |
digit_class | Requested digit classification |
float_class | Requested floating point classification |
pad | Padding character for filling in minimum width |
always_signed | Whether to output a + for positive numbers |
class_prefix | Whether to output a prefix based on the numeric base |
numeric_pad | Whether to use numeric padding rules |
The ST::format_spec
structure defines the parameters for formatting an object
with string_theory's formatters. It is usually populated by the format call
itself (see the Format string reference guide for details),
but it can also be modified if necessary within the type formatter.
Mostly, it is useful for deciding how to format something based on the user's
requested formatting rules.
enum alignment_t
{
align_default,
align_left,
align_right
};
Indicates the text alignment for objects.
- align_default: Use the formatter-specific default alignment for the given data. For built-in formatters, this is right for numbers and left for everything else.
- align_left: Align text to the left of the reserved format space.
- align_right: Align text to the right of the reserved format space.
enum digit_class_t
{
digit_default,
digit_dec,
digit_hex,
digit_hex_upper,
digit_oct,
digit_bin,
digit_char
};
Specifies the number base to use when formatting numeric objects.
-
digit_default: Use the default digit class. This is
digit_dec
for integers anddigit_char
for character types. - digit_dec: Format number in decimal (base 10).
- digit_hex: Format number in lower-case hexadecimal.
- digit_hex_upper: Format number in upper-case hexadecimal.
- digit_oct: Format number in octal (base 8).
- digit_bin: Format number in binary.
- digit_char: Format number as a single Unicode character (encoded as UTF-8).
enum float_class_t
{
float_default,
float_fixed,
float_exp,
float_exp_upper
};
Specifies the formatting type to use when formatting floating-point numbers.
-
float_default: Auto-determine the formatting rules. This is equivalent to
the
'%g'
printf-style format. -
float_fixed: Format number in fixed-point. This is equivalent to the
'%f'
printf-style format. -
float_exp: Format number in exponent notation. This is equivalent to
the
'%e'
printf-style format. -
float_exp_upper: Identical to
float_exp
, except that an upper-case 'E' is used to separate the base from the exponent.
Signature |
---|
format_spec() noexcept |
Default constructor. Sets all properties to their default values.
Signature |
---|
ST::alignment_t alignment |
Which direction to align the text. Note that this value is only meaningful
if the actual length of the formatted text is shorter than the specified
minimum_length. For the case of align_default
, it is
up to the formatter to decide which direction to align the text. For the
built-in formatters, align_right
is used for numerics, and align_left
is
used for everything else.
Note that when numeric_pad is true
, this value will not be
used, since numeric padding is always on the left side of the number.
Signature |
---|
bool always_signed |
If this property is true
, then a '+'
should be added to the left of numeric
formats for positive and unsigned values.
Signature |
---|
int arg_index |
If this parameter is greater than zero, then it specifies which format argument should be used for the format. If it is less than zero (the default), then the next argument in order should be used for formatting.
Since string_theory 2.0.
Signature |
---|
bool class_prefix |
If this property is true
, then a digit_class-specific prefix
should be added to the left of numeric formats.
The following prefixes are added:
-
digit_bin:
'0b'
-
digit_hex:
'0x'
-
digit_hex_upper:
'0X'
-
digit_oct:
'0'
- Others: (no prefix)
Signature |
---|
ST::digit_class_t digit_class |
How to format integer and character objects. For details, see the digit_class_t enumeration documentation.
Signature |
---|
ST::float_class_t float_class |
How to render floating point numbers. For details, see the float_class_t enumeration documentation.
Signature |
---|
int minimum_length |
The minimum number of characters to use in formatting the object. If the
actual formatted length is less than minimum_length
, the extra space will
be filled in with pad characters.
Signature |
---|
bool numeric_pad |
If this property is true
, then numeric rules should be used when applying
the pad character (usually '0'
) to the left side of the format.
Specifically:
- Other prefixes (like the class_prefix and the sign) should be placed before the padding.
- Alignment is always right -- the zeros should always be on the left side of the formatted digits.
Signature |
---|
char pad |
The character to use when padding formatted strings. If the resulting format is shorter than minimum_length, this (ASCII) character will be used to fill in from either the left or right, depending on the value of the alignment property.
Signature |
---|
int precision |
The precision to use when formatting floating-point numbers. That is, the
number of digits after the radix for float_fixed
and float_exp
numbers, or
the total number of significant digits for float_default
numbers.