Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: src/inspector/string-16.cc

Issue 2410933002: [inspector] fix timestamp formatting with non C locales (Closed)
Patch Set: a Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/string-16.h ('k') | src/inspector/v8-console.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/string-16.cc
diff --git a/src/inspector/string-16.cc b/src/inspector/string-16.cc
index e39b87c17f8f035201e9ea4b4835ea3da6c52800..f6084602f421085127603f146f2c9618eb1b1962 100644
--- a/src/inspector/string-16.cc
+++ b/src/inspector/string-16.cc
@@ -8,8 +8,10 @@
#include <cctype>
#include <cstdlib>
#include <cstring>
+#include <iomanip>
#include <limits>
#include <locale>
+#include <sstream>
#include <string>
#include "src/base/platform/platform.h"
@@ -381,26 +383,19 @@ String16 String16::fromInteger(size_t number) {
// static
String16 String16::fromDouble(double number) {
- const size_t kBufferSize = 100;
- char buffer[kBufferSize];
- v8::base::OS::SNPrintF(buffer, kBufferSize, "%f", number);
- return String16(buffer);
+ std::ostringstream s;
+ s.imbue(std::locale("C"));
+ s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10)
+ << number;
+ return String16(s.str().c_str());
}
// static
-String16 String16::fromDoublePrecision3(double number) {
- const size_t kBufferSize = 100;
- char buffer[kBufferSize];
- v8::base::OS::SNPrintF(buffer, kBufferSize, "%.3g", number);
- return String16(buffer);
-}
-
-// static
-String16 String16::fromDoublePrecision6(double number) {
- const size_t kBufferSize = 100;
- char buffer[kBufferSize];
- v8::base::OS::SNPrintF(buffer, kBufferSize, "%.6g", number);
- return String16(buffer);
+String16 String16::fromDouble(double number, int precision) {
+ std::ostringstream s;
+ s.imbue(std::locale("C"));
+ s << std::fixed << std::setprecision(precision) << number;
+ return String16(s.str().c_str());
}
int String16::toInteger(bool* ok) const {
« no previous file with comments | « src/inspector/string-16.h ('k') | src/inspector/v8-console.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698