forked from ars3niy/tdlib-purple
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathformat.cpp
33 lines (27 loc) · 939 Bytes
/
format.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "format.h"
#include <fmt/format.h>
std::string formatMessage(const char *fmt, std::initializer_list<std::string> args)
{
fmt::dynamic_format_arg_store<fmt::format_context> fa;
for (const std::string &arg: args)
fa.push_back(arg);
return fmt::vformat(fmt, fa);
}
std::string formatMessage(const char *fmt, const std::string &s)
{
return formatMessage(fmt, {s});
}
std::string formatDuration(int32_t seconds)
{
int32_t hours = seconds / 3600;
seconds -= hours * 3600;
int32_t minutes = seconds / 60;
seconds -= minutes * 60;
// TRANSLATOR: Time format. For HH:MM:SS use "{:02}:{:02}:{:02}" without the quotes.
return fmt::format(_("{:02}:{:02}:{:02}"), hours, minutes, seconds);
}
void purpleDebug(const char *fmt, std::initializer_list<std::string> args)
{
std::string message = formatMessage(fmt, args);
purple_debug_misc(config::pluginId, "%s\n", message.c_str());
}