ENH: MSVS 2013 snprintf compatible substitute

Simplify the backwards compatible snprintf configuration for pre
1900 version of MSVC.  Otherwise prefer C++11 syntax using std::snprintf.
This commit is contained in:
Hans Johnson
2018-12-12 13:31:55 -06:00
committed by Christopher Dunn
parent ccd077ffce
commit 5c8e539af4
5 changed files with 37 additions and 27 deletions

View File

@@ -28,11 +28,7 @@ struct Options {
static JSONCPP_STRING normalizeFloatingPointStr(double value) {
char buffer[32];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
#else
snprintf(buffer, sizeof(buffer), "%.16g", value);
#endif
jsoncpp_snprintf(buffer, sizeof(buffer), "%.16g", value);
buffer[sizeof(buffer) - 1] = 0;
JSONCPP_STRING s(buffer);
JSONCPP_STRING::size_type index = s.find_last_of("eE");
@@ -105,11 +101,7 @@ static void printValueTree(FILE* fout,
Json::ArrayIndex size = value.size();
for (Json::ArrayIndex index = 0; index < size; ++index) {
static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
sprintf_s(buffer, sizeof(buffer), "[%u]", index);
#else
snprintf(buffer, sizeof(buffer), "[%u]", index);
#endif
jsoncpp_snprintf(buffer, sizeof(buffer), "[%u]", index);
printValueTree(fout, value[index], path + buffer);
}
} break;