Add FMT_CAPTURE_W
This commit is contained in:
parent
7f96af5eef
commit
c26d7311f4
4
format.h
4
format.h
@ -2940,6 +2940,8 @@ inline internal::NamedArg<wchar_t, T> arg(WStringRef name, const T &arg) {
|
|||||||
|
|
||||||
#define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id)
|
#define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id)
|
||||||
|
|
||||||
|
#define FMT_CAPTURE_ARG_W_(id, index) ::fmt::arg(L#id, id)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Convenient macro to capture the arguments' names and values into several
|
Convenient macro to capture the arguments' names and values into several
|
||||||
@ -2956,6 +2958,8 @@ inline internal::NamedArg<wchar_t, T> arg(WStringRef name, const T &arg) {
|
|||||||
*/
|
*/
|
||||||
#define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__)
|
#define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__)
|
||||||
|
|
||||||
namespace fmt {
|
namespace fmt {
|
||||||
FMT_VARIADIC(std::string, format, StringRef)
|
FMT_VARIADIC(std::string, format, StringRef)
|
||||||
FMT_VARIADIC_W(std::wstring, format, WStringRef)
|
FMT_VARIADIC_W(std::wstring, format, WStringRef)
|
||||||
|
|||||||
@ -613,6 +613,7 @@ TEST(FormatterTest, NamedArg) {
|
|||||||
EXPECT_EQ("BBAACC", format("{1}{b}{0}{a}{2}{c}", FMT_CAPTURE(a, b, c)));
|
EXPECT_EQ("BBAACC", format("{1}{b}{0}{a}{2}{c}", FMT_CAPTURE(a, b, c)));
|
||||||
EXPECT_EQ(" A", format("{a:>2}", FMT_CAPTURE(a)));
|
EXPECT_EQ(" A", format("{a:>2}", FMT_CAPTURE(a)));
|
||||||
EXPECT_THROW_MSG(format("{a+}", FMT_CAPTURE(a)), FormatError, "missing '}' in format string");
|
EXPECT_THROW_MSG(format("{a+}", FMT_CAPTURE(a)), FormatError, "missing '}' in format string");
|
||||||
|
EXPECT_THROW_MSG(format("{a}"), FormatError, "argument not found");
|
||||||
EXPECT_THROW_MSG(format("{d}", FMT_CAPTURE(a, b, c)), FormatError, "argument not found");
|
EXPECT_THROW_MSG(format("{d}", FMT_CAPTURE(a, b, c)), FormatError, "argument not found");
|
||||||
EXPECT_THROW_MSG(format("{a}{}", FMT_CAPTURE(a)),
|
EXPECT_THROW_MSG(format("{a}{}", FMT_CAPTURE(a)),
|
||||||
FormatError, "cannot switch from manual to automatic argument indexing");
|
FormatError, "cannot switch from manual to automatic argument indexing");
|
||||||
@ -620,6 +621,8 @@ TEST(FormatterTest, NamedArg) {
|
|||||||
FormatError, "cannot switch from automatic to manual argument indexing");
|
FormatError, "cannot switch from automatic to manual argument indexing");
|
||||||
EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4)));
|
EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4)));
|
||||||
EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2)));
|
EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2)));
|
||||||
|
int n = 100;
|
||||||
|
EXPECT_EQ(L"n=100", format(L"n={n}", FMT_CAPTURE_W(n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, AutoArgIndex) {
|
TEST(FormatterTest, AutoArgIndex) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user