format -> vformat

This commit is contained in:
Victor Zverovich 2016-08-26 09:10:23 -07:00
parent 43c0095aa3
commit b903f5c123
2 changed files with 11 additions and 6 deletions

View File

@ -226,7 +226,7 @@ FMT_FUNC void SystemError::init(
int err_code, CStringRef format_str, format_args args) { int err_code, CStringRef format_str, format_args args) {
error_code_ = err_code; error_code_ = err_code;
MemoryWriter w; MemoryWriter w;
format_system_error(w, err_code, format(format_str, args)); format_system_error(w, err_code, vformat(format_str, args));
std::runtime_error &base = *this; std::runtime_error &base = *this;
base = std::runtime_error(w.str()); base = std::runtime_error(w.str());
} }

View File

@ -3122,6 +3122,12 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
*/ */
FMT_API void print_colored(Color c, CStringRef format, format_args args); FMT_API void print_colored(Color c, CStringRef format, format_args args);
inline std::string vformat(CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
return w.str();
}
/** /**
\rst \rst
Formats arguments and returns the result as a string. Formats arguments and returns the result as a string.
@ -3131,10 +3137,10 @@ FMT_API void print_colored(Color c, CStringRef format, format_args args);
std::string message = format("The answer is {}", 42); std::string message = format("The answer is {}", 42);
\endrst \endrst
*/ */
inline std::string format(CStringRef format_str, format_args args) { template <typename... Args>
MemoryWriter w; inline std::string format(CStringRef format_str, const Args & ... args) {
w.write(format_str, args); auto vargs = internal::make_format_args<BasicFormatter<char>>(args...);
return w.str(); vformat(format_str, format_args(vargs.TYPES, vargs.data()));
} }
inline std::wstring format(WCStringRef format_str, format_args args) { inline std::wstring format(WCStringRef format_str, format_args args) {
@ -3389,7 +3395,6 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
#define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__) #define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__)
namespace fmt { namespace fmt {
FMT_VARIADIC(std::string, format, CStringRef)
FMT_VARIADIC_W(std::wstring, format, WCStringRef) FMT_VARIADIC_W(std::wstring, format, WCStringRef)
FMT_VARIADIC(void, print, CStringRef) FMT_VARIADIC(void, print, CStringRef)
FMT_VARIADIC(void, print, std::FILE *, CStringRef) FMT_VARIADIC(void, print, std::FILE *, CStringRef)