Merge pull request #1987 from derek-zhou/master

seperate Mu::format and Mu::vformat
This commit is contained in:
Dirk-Jan C. Binnema 2021-04-22 22:39:07 +03:00 committed by GitHub
commit 6307bc02c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 7 deletions

View File

@ -481,7 +481,7 @@ Store::set_dirstamp (const std::string& path, time_t tstamp)
LOCKED;
std::array<char, 2*sizeof(tstamp)+1> data{};
const std::size_t len = g_snprintf (data.data(), data.size(), "%zx", tstamp);
const std::size_t len = g_snprintf (data.data(), data.size(), "%zx", (size_t)tstamp);
priv_->writable_db().set_metadata(path, std::string{data.data(), len});
priv_->dirty();

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");
}