From 757231cc6e777b8f4717d1467ef7efa01c7fde15 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Wed, 3 Jan 2018 17:41:16 +0000 Subject: Add the fmt library (#4065) * Replaces AppendVPrintf with fmt::sprintf * fmt::ArgList now used as a type safe alternative to varargs. * Removed SIZE_T_FMT compatibility macros. fmt::sprintf is fully portable and supports %zu. * Adds FLOG functions to log with fmt's native formatting style. --- src/StringUtils.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/StringUtils.h') diff --git a/src/StringUtils.h b/src/StringUtils.h index 12227014d..a74239ec8 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -22,21 +22,24 @@ typedef std::map AStringMap; -/** Add the formated string to the existing data in the string. -Returns a_Dst. */ -extern AString & AppendVPrintf(AString & a_Dst, const char * format, va_list args) FORMATSTRING(2, 0); - /** Output the formatted text into the string. Returns a_Dst. */ -extern AString & Printf (AString & a_Dst, const char * format, ...) FORMATSTRING(2, 3); +extern AString & Printf(AString & a_Dst, const char * format, fmt::ArgList args); +FMT_VARIADIC(AString &, Printf, AString &, const char *) /** Output the formatted text into string Returns the formatted string by value. */ -extern AString Printf(const char * format, ...) FORMATSTRING(1, 2); +extern AString Printf(const char * format, fmt::ArgList args); +FMT_VARIADIC(AString, Printf, const char *) -/** Add the formatted string to the existing data in the string. -Returns a_Dst */ -extern AString & AppendPrintf (AString & a_Dst, const char * format, ...) FORMATSTRING(2, 3); +/** Add the formated string to the existing data in the string. +Returns a_Dst. */ +template +extern AString & AppendPrintf(AString & a_Dst, const char * format, const Args & ... args) +{ + a_Dst += Printf(format, args...); + return a_Dst; +} /** Split the string at any of the listed delimiters. Return the splitted strings as a stringvector. */ @@ -91,8 +94,7 @@ extern AString UnicodeCharToUtf8(unsigned a_UnicodeChar); /** Converts a UTF-8 string into a UTF-16 BE string. */ extern std::u16string UTF8ToRawBEUTF16(const AString & a_String); -/** Creates a nicely formatted HEX dump of the given memory block. -Max a_BytesPerLine is 120. */ +/** Creates a nicely formatted HEX dump of the given memory block. */ extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine); /** Returns a copy of a_Message with all quotes and backslashes escaped by a backslash. */ -- cgit v1.2.3