Adjust Format-inl.h to work with MSVC
authorOrvid King <blah38621@gmail.com>
Tue, 18 Aug 2015 18:53:33 +0000 (11:53 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Tue, 18 Aug 2015 19:20:20 +0000 (12:20 -0700)
Summary: Originally #247, which was closed before being merged, this doesn't change the behavior of the formatting function now.
Closes #297

Reviewed By: @yfeldblum

Differential Revision: D2340712

Pulled By: @sgolemon

folly/Format-inl.h

index 56adcd0132a739b76447f1cb31abde8db08df870..64591d6af702e8dfadafffeb2737b87def6a5132 100644 (file)
@@ -490,8 +490,21 @@ class FormatValue<
                   "' specifier");
 
       valBufBegin = valBuf + 3;  // room for sign and base prefix
+#ifdef _MSC_VER
+      char valBuf2[valBufSize];
+      snprintf(valBuf2, valBufSize, "%ju", static_cast<uintmax_t>(uval));
+      int len = GetNumberFormat(
+        LOCALE_USER_DEFAULT,
+        0,
+        valBuf2,
+        nullptr,
+        valBufBegin,
+        (int)((valBuf + valBufSize) - valBufBegin)
+      );
+#else
       int len = snprintf(valBufBegin, (valBuf + valBufSize) - valBufBegin,
                          "%'ju", static_cast<uintmax_t>(uval));
+#endif
       // valBufSize should always be big enough, so this should never
       // happen.
       assert(len < valBuf + valBufSize - valBufBegin);