composite_format
module · ferroui-base · v0.5.0
module composite_format
Composite formatting: the string.Format of the managed runtime.
format and format_arg use the invariant culture, the _with
forms the number and date formats of a CultureInfo and
format_values those of the current culture.
A composite format string is literal text with format items
{index[,alignment][:formatString]}. {{ and }} are literal braces.
The results match the managed runtime (version 10) character for
character for the supported argument types.
Supported
Format items: index, repeated and out-of-order indices, alignment (
{0,10}right-aligns,{0,-10}left-aligns; the width counts UTF-16 code units), format strings,{{/}}escapes, spaces after the index and around the alignment. A}ends the format string of an item and a{inside it is an error, as in the managed runtime.Arguments: null (empty text), strings, booleans (
True/False), characters, signed and unsigned integers and floating point numbers. Strings, booleans and characters ignore the format string.Default number formatting (no format string): integers as decimal digits; floating point numbers as the shortest text that round-trips, switching to exponent notation (
1E+17,1E-05) when the value is below0.0001or its integer part has more digits than both the text and the round-trip precision (17 forf64, 9 forf32);NaN,Infinity,-Infinity,-0.Standard numeric format strings, upper and lower case, with an optional precision of up to 999,999,999:
C(currency symbol¤, negative in parentheses),D(integers only),E,F,G,N,P(12.50 %),R,X(integers only; negative values in two's complement of the integer's width),B(integers only).Custom numeric format strings:
0,#,.,,as group separator and as number scaling,%,‰,;sections (positive; negative; zero),E0/E+0/E-0/e0/e+0/e-0exponents, quoted literals ('..',".."),\escapes; every other character is copied.Rounding: standard format strings round floating point numbers correctly from the exact binary value, exact midpoints going to the even digit (
0.125withF2is0.12,2.5withF0is2); custom format strings first take 15 (f64) or 7 (f32) significant digits and then round midpoints away from zero (2.5with0is3); integers round midpoints away from zero (12350withE2is1.24E+004).Decimals (standard and custom numeric format strings), dates and times (
DateTime,DateTimeOffset: standard and custom date and time format strings) and time spans, formatted by their own types with the format string of the item.Cultures: decimal and group separators, group sizes, the negative and positive signs, the currency and percent symbols and patterns, the default numbers of decimal digits and the symbols of the values that are not numbers come from the
NumberFormatInfoof the culture; dates use itsDateTimeFormatInfo.
Not supported
- Custom format providers.
- GUID and enumeration format strings and arbitrary precision numbers.
Values of such types are formatted through their registered display
form and ignore the format string of the item. The
g/Gformats of a time span use.as the decimal separator in every culture. - 128-bit integers and half precision floats.
Contents
FormatArg— enumFormatError— enumformat— functionformat_with— functionformat_arg— functionformat_arg_with— functionformat_values— functionformat_values_with— function
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.