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

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

Issue 2410933002: [inspector] fix timestamp formatting with non C locales (Closed)
Patch Set: using stringstream 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
Index: src/inspector/string-16.cc
diff --git a/src/inspector/string-16.cc b/src/inspector/string-16.cc
index e39b87c17f8f035201e9ea4b4835ea3da6c52800..b9ee8041195393463bef9655c764b63afa9acd19 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,27 @@ 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);
+ std::ostringstream s;
+ s.imbue(std::locale("C"));
+ s << std::fixed << std::setprecision(3) << number;
+ return String16(s.str().c_str());
}
// static
String16 String16::fromDoublePrecision6(double number) {
dgozman 2016/10/11 21:03:35 Let's combine with previous one.
kozy 2016/10/11 22:26:15 Done.
- const size_t kBufferSize = 100;
- char buffer[kBufferSize];
- v8::base::OS::SNPrintF(buffer, kBufferSize, "%.6g", number);
- return String16(buffer);
+ std::ostringstream s;
+ s.imbue(std::locale("C"));
+ s << std::fixed << std::setprecision(6) << number;
+ return String16(s.str().c_str());
}
int String16::toInteger(bool* ok) const {

Powered by Google App Engine
This is Rietveld 408576698