seperate Mu::format and Mu::vformat

This commit is contained in:
Derek Zhou
2021-04-22 18:32:38 +00:00
parent 5edc5a886a
commit dc6f76d74d
6 changed files with 9 additions and 7 deletions

View File

@ -67,7 +67,7 @@ struct Error final: public std::exception {
Error(Code codearg, const char *frm, ...): code_{codearg} {
va_list args;
va_start(args, frm);
what_ = format(frm, args);
what_ = vformat(frm, args);
va_end(args);
}
@ -89,7 +89,7 @@ struct Error final: public std::exception {
va_list args;
va_start(args, frm);
what_ = format(frm, args);
what_ = vformat(frm, args);
va_end(args);
if (err && *err)

View File

@ -32,7 +32,7 @@ parsing_error(size_t pos, const char* frm, ...)
{
va_list args;
va_start(args, frm);
auto msg = format(frm, args);
auto msg = vformat(frm, args);
va_end(args);
if (pos == 0)

View File

@ -204,14 +204,14 @@ Mu::quote (const std::string& str)
va_list args;
va_start (args, frm);
auto str = format(frm, args);
auto str = vformat(frm, args);
va_end (args);
return str;
}
std::string
Mu::format (const char *frm, va_list args)
Mu::vformat (const char *frm, va_list args)
{
char *s{};
const auto res = g_vasprintf (&s, frm, args);

View File

@ -104,7 +104,7 @@ std::string format (const char *frm, ...) __attribute__((format(printf, 1, 2)));
*
* @return a formatted string
*/
std::string format (const char *frm, va_list args) __attribute__((format(printf, 1, 0)));
std::string vformat (const char *frm, va_list args) __attribute__((format(printf, 1, 0)));
/**

View File

@ -168,6 +168,8 @@ test_clean ()
static void
test_format ()
{
g_assert_true (format ("hello %s", "world") ==
"hello world");
g_assert_true (format ("hello %s, %u", "world", 123) ==
"hello world, 123");
}