From 08483a01383607042b238801f1ba292d9550aadb Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 14 Mar 2017 14:55:22 +0000 Subject: [PATCH] Fixed a VS 2017 compiler warning --- modules/juce_core/text/juce_String.cpp | 22 ++++++++++++---------- modules/juce_core/text/juce_String.h | 6 +++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 7bed65bf14..d063e9011f 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -1867,8 +1867,7 @@ bool String::containsNonWhitespaceChars() const noexcept return false; } -// Note! The format parameter here MUST NOT be a reference, otherwise MS's va_start macro fails to work (but still compiles). -String String::formatted (const String pf, ... ) +String String::formattedRaw (const char* pf, ...) { size_t bufferSize = 256; @@ -1877,19 +1876,22 @@ String String::formatted (const String pf, ... ) va_list args; va_start (args, pf); - #if JUCE_WINDOWS - HeapBlock temp (bufferSize); - const int num = (int) _vsnwprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args); - #elif JUCE_ANDROID + #if JUCE_ANDROID HeapBlock temp (bufferSize); - int num = (int) vsnprintf (temp.getData(), bufferSize - 1, pf.toUTF8(), args); + int num = (int) vsnprintf (temp.getData(), bufferSize - 1, pf, args); if (num >= static_cast (bufferSize)) num = -1; - #else + #else + String wideCharVersion (pf); HeapBlock temp (bufferSize); - const int num = (int) vswprintf (temp.getData(), bufferSize - 1, pf.toWideCharPointer(), args); + const int num = (int) + #if JUCE_WINDOWS + _vsnwprintf + #else + vswprintf #endif - + (temp.getData(), bufferSize - 1, wideCharVersion.toWideCharPointer(), args); + #endif va_end (args); if (num > 0) diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index d2e63c53c9..b9c9235041 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -919,7 +919,8 @@ public: on the platform, it may be using wchar_t or char character types, so that even string literals can't be safely used as parameters if you're writing portable code. */ - static String formatted (const String formatString, ... ); + template + static String formatted (const String& formatStr, Args... args) { return formattedRaw (formatStr.toRawUTF8(), args...); } //============================================================================== // Numeric conversions.. @@ -1274,6 +1275,9 @@ private: // to bools (this is possible because the compiler can add an implicit cast // via a const char*) operator bool() const noexcept { return false; } + + //============================================================================== + static String formattedRaw (const char*, ...); }; //==============================================================================