mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Implement the L specifier
This commit is contained in:
@ -81,8 +81,8 @@ The general form of a *standard format specifier* is:
|
|||||||
sign: "+" | "-" | " "
|
sign: "+" | "-" | " "
|
||||||
width: `integer` | "{" `arg_id` "}"
|
width: `integer` | "{" `arg_id` "}"
|
||||||
precision: `integer` | "{" `arg_id` "}"
|
precision: `integer` | "{" `arg_id` "}"
|
||||||
type: `int_type` | "a" | "A" | "c" | "e" | "E" | "f" | "F" | "g" | "G" | "p" | "s"
|
type: `int_type` | "a" | "A" | "c" | "e" | "E" | "f" | "F" | "g" | "G" | "L" | "p" | "s"
|
||||||
int_type: "b" | "B" | "d" | "n" | "o" | "x" | "X"
|
int_type: "b" | "B" | "d" | "o" | "x" | "X"
|
||||||
|
|
||||||
The *fill* character can be any Unicode code point other than ``'{'`` or
|
The *fill* character can be any Unicode code point other than ``'{'`` or
|
||||||
``'}'``. The presence of a fill character is signaled by the character following
|
``'}'``. The presence of a fill character is signaled by the character following
|
||||||
@ -143,7 +143,7 @@ conversions, trailing zeros are not removed from the result.
|
|||||||
.. ifconfig:: False
|
.. ifconfig:: False
|
||||||
|
|
||||||
The ``','`` option signals the use of a comma for a thousands separator.
|
The ``','`` option signals the use of a comma for a thousands separator.
|
||||||
For a locale aware separator, use the ``'n'`` integer presentation type
|
For a locale aware separator, use the ``'L'`` integer presentation type
|
||||||
instead.
|
instead.
|
||||||
|
|
||||||
*width* is a decimal integer defining the minimum field width. If not
|
*width* is a decimal integer defining the minimum field width. If not
|
||||||
@ -214,9 +214,9 @@ The available integer presentation types are:
|
|||||||
| | ``'#'`` option with this type adds the prefix ``"0X"`` |
|
| | ``'#'`` option with this type adds the prefix ``"0X"`` |
|
||||||
| | to the output value. |
|
| | to the output value. |
|
||||||
+---------+----------------------------------------------------------+
|
+---------+----------------------------------------------------------+
|
||||||
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
|
| ``'L'`` | Locale-specific format. This is the same as ``'d'``, |
|
||||||
| | the current locale setting to insert the appropriate |
|
| | except that it uses the current locale setting to insert |
|
||||||
| | number separator characters. |
|
| | the appropriate number separator characters. |
|
||||||
+---------+----------------------------------------------------------+
|
+---------+----------------------------------------------------------+
|
||||||
| none | The same as ``'d'``. |
|
| none | The same as ``'d'``. |
|
||||||
+---------+----------------------------------------------------------+
|
+---------+----------------------------------------------------------+
|
||||||
@ -261,9 +261,9 @@ The available presentation types for floating-point values are:
|
|||||||
| | ``'E'`` if the number gets too large. The |
|
| | ``'E'`` if the number gets too large. The |
|
||||||
| | representations of infinity and NaN are uppercased, too. |
|
| | representations of infinity and NaN are uppercased, too. |
|
||||||
+---------+----------------------------------------------------------+
|
+---------+----------------------------------------------------------+
|
||||||
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
|
| ``'L'`` | Locale-specific format. This is the same as ``'g'``, |
|
||||||
| | the current locale setting to insert the appropriate |
|
| | except that it uses the current locale setting to insert |
|
||||||
| | number separator characters. |
|
| | the appropriate number separator characters. |
|
||||||
+---------+----------------------------------------------------------+
|
+---------+----------------------------------------------------------+
|
||||||
| none | Similar to ``'g'``, except that fixed-point notation, |
|
| none | Similar to ``'g'``, except that fixed-point notation, |
|
||||||
| | when used, has at least one digit past the decimal |
|
| | when used, has at least one digit past the decimal |
|
||||||
@ -403,7 +403,7 @@ Using the comma as a thousands separator::
|
|||||||
|
|
||||||
#include <fmt/locale.h>
|
#include <fmt/locale.h>
|
||||||
|
|
||||||
auto s = fmt::format(std::locale("en_US.UTF-8"), "{:n}", 1234567890);
|
auto s = fmt::format(std::locale("en_US.UTF-8"), "{:L}", 1234567890);
|
||||||
// s == "1,234,567,890"
|
// s == "1,234,567,890"
|
||||||
|
|
||||||
.. ifconfig:: False
|
.. ifconfig:: False
|
||||||
|
@ -1236,6 +1236,7 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
|
|||||||
handler.on_oct();
|
handler.on_oct();
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
|
case 'L':
|
||||||
handler.on_num();
|
handler.on_num();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1256,7 +1256,7 @@ TEST(FormatterTest, FormatShort) {
|
|||||||
TEST(FormatterTest, FormatInt) {
|
TEST(FormatterTest, FormatInt) {
|
||||||
EXPECT_THROW_MSG(format("{0:v", 42), format_error,
|
EXPECT_THROW_MSG(format("{0:v", 42), format_error,
|
||||||
"missing '}' in format string");
|
"missing '}' in format string");
|
||||||
check_unknown_types(42, "bBdoxXn", "integer");
|
check_unknown_types(42, "bBdoxXnL", "integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatBin) {
|
TEST(FormatterTest, FormatBin) {
|
||||||
@ -1397,6 +1397,7 @@ TEST(FormatterTest, FormatOct) {
|
|||||||
|
|
||||||
TEST(FormatterTest, FormatIntLocale) {
|
TEST(FormatterTest, FormatIntLocale) {
|
||||||
EXPECT_EQ("1234", format("{:n}", 1234));
|
EXPECT_EQ("1234", format("{:n}", 1234));
|
||||||
|
EXPECT_EQ("1234", format("{:L}", 1234));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConvertibleToLongLong {
|
struct ConvertibleToLongLong {
|
||||||
@ -1491,7 +1492,7 @@ TEST(FormatterTest, FormatLongDouble) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatChar) {
|
TEST(FormatterTest, FormatChar) {
|
||||||
const char types[] = "cbBdoxXn";
|
const char types[] = "cbBdoxXnL";
|
||||||
check_unknown_types('a', types, "char");
|
check_unknown_types('a', types, "char");
|
||||||
EXPECT_EQ("a", format("{0}", 'a'));
|
EXPECT_EQ("a", format("{0}", 'a'));
|
||||||
EXPECT_EQ("z", format("{0:c}", 'z'));
|
EXPECT_EQ("z", format("{0:c}", 'z'));
|
||||||
|
Reference in New Issue
Block a user