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/OSSupport/CMakeLists.txt | 1 + src/OSSupport/File.cpp | 8 ++------ src/OSSupport/File.h | 17 ++++++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/OSSupport') diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index e6fb37987..55d2dd87a 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -48,4 +48,5 @@ endif() if(NOT MSVC) add_library(OSSupport ${SRCS} ${HDRS}) + target_link_libraries(OSSupport fmt::fmt) endif() diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 166de8f46..8b91cc2a4 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -690,13 +690,9 @@ AString cFile::GetExecutableExt(void) -int cFile::Printf(const char * a_Fmt, ...) +int cFile::Printf(const char * a_Fmt, fmt::ArgList a_ArgList) { - AString buf; - va_list args; - va_start(args, a_Fmt); - AppendVPrintf(buf, a_Fmt, args); - va_end(args); + AString buf = ::Printf(a_Fmt, a_ArgList); return Write(buf.c_str(), buf.length()); } diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 28485d9f8..59bb61974 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -39,12 +39,14 @@ class cFile public: // tolua_end - - #ifdef _WIN32 - static const char PathSeparator = '\\'; - #else - static const char PathSeparator = '/'; - #endif + inline static char PathSeparator() + { + #ifdef _WIN32 + return '\\'; + #else + return '/'; + #endif + } /** The mode in which to open the file */ enum eMode @@ -161,7 +163,8 @@ public: /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp - int Printf(const char * a_Fmt, ...) FORMATSTRING(2, 3); + int Printf(const char * a_Fmt, fmt::ArgList); + FMT_VARIADIC(int, Printf, const char *) /** Flushes all the bufferef output into the file (only when writing) */ void Flush(void); -- cgit v1.2.3