Skip to content

Commit

Permalink
Replace vararg function with template varargs
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed May 25, 2024
1 parent e642130 commit 171b961
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include "logging.h"

#include <cstdarg>
#include <cstdio>
#include <optional>

Expand All @@ -57,22 +56,26 @@ Colour Colour::from_argb32(uint32_t argb) {
#endif /* BUILD_COLOUR_NAME_MAP */

std::optional<Colour> inline no_colour() { return std::nullopt; }
template <typename... Args>
std::optional<Colour> parse_error(const std::string &color_str,
const char *format...) {
va_list args;
va_start(args, format);
size_t len = snprintf(nullptr, 0, format, args);
const char *format, Args... args) {
size_t len = snprintf(nullptr, 0, format, args...);

char *reason = new char[len + 1];
snprintf(reason, len + 1, format, args);
va_end(args);
snprintf(reason, len + 1, format, args...);

CRIT_ERR("can't parse color '%s' (len: %d): %s", color_str.c_str(),
color_str.length(), reason);
delete[] reason;

return ERROR_COLOUR;
}
std::optional<Colour> parse_error(const std::string &color_str,
const char *reason) {
CRIT_ERR("can't parse color '%s' (len: %d): %s", color_str.c_str(),
color_str.length(), reason);
return ERROR_COLOUR;
}

std::optional<Colour> parse_color_name(const std::string &name) {
const rgb *value = color_name_hash::in_word_set(name.c_str(), name.length());
Expand Down

0 comments on commit 171b961

Please sign in to comment.