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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/inspector/string-16.h ('k') | src/inspector/v8-console.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/inspector/string-16.h" 5 #include "src/inspector/string-16.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <cstdlib> 9 #include <cstdlib>
10 #include <cstring> 10 #include <cstring>
11 #include <iomanip>
11 #include <limits> 12 #include <limits>
12 #include <locale> 13 #include <locale>
14 #include <sstream>
13 #include <string> 15 #include <string>
14 16
15 #include "src/base/platform/platform.h" 17 #include "src/base/platform/platform.h"
16 #include "src/inspector/protocol-platform.h" 18 #include "src/inspector/protocol-platform.h"
17 19
18 namespace v8_inspector { 20 namespace v8_inspector {
19 21
20 namespace { 22 namespace {
21 23
22 bool isASCII(UChar c) { return !(c & ~0x7F); } 24 bool isASCII(UChar c) { return !(c & ~0x7F); }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // static 376 // static
375 String16 String16::fromInteger(size_t number) { 377 String16 String16::fromInteger(size_t number) {
376 const size_t kBufferSize = 50; 378 const size_t kBufferSize = 50;
377 char buffer[kBufferSize]; 379 char buffer[kBufferSize];
378 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); 380 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number);
379 return String16(buffer); 381 return String16(buffer);
380 } 382 }
381 383
382 // static 384 // static
383 String16 String16::fromDouble(double number) { 385 String16 String16::fromDouble(double number) {
384 const size_t kBufferSize = 100; 386 std::ostringstream s;
385 char buffer[kBufferSize]; 387 s.imbue(std::locale("C"));
386 v8::base::OS::SNPrintF(buffer, kBufferSize, "%f", number); 388 s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10)
387 return String16(buffer); 389 << number;
390 return String16(s.str().c_str());
388 } 391 }
389 392
390 // static 393 // static
391 String16 String16::fromDoublePrecision3(double number) { 394 String16 String16::fromDouble(double number, int precision) {
392 const size_t kBufferSize = 100; 395 std::ostringstream s;
393 char buffer[kBufferSize]; 396 s.imbue(std::locale("C"));
394 v8::base::OS::SNPrintF(buffer, kBufferSize, "%.3g", number); 397 s << std::fixed << std::setprecision(precision) << number;
395 return String16(buffer); 398 return String16(s.str().c_str());
396 }
397
398 // static
399 String16 String16::fromDoublePrecision6(double number) {
400 const size_t kBufferSize = 100;
401 char buffer[kBufferSize];
402 v8::base::OS::SNPrintF(buffer, kBufferSize, "%.6g", number);
403 return String16(buffer);
404 } 399 }
405 400
406 int String16::toInteger(bool* ok) const { 401 int String16::toInteger(bool* ok) const {
407 return charactersToInteger(characters16(), length(), ok); 402 return charactersToInteger(characters16(), length(), ok);
408 } 403 }
409 404
410 String16 String16::stripWhiteSpace() const { 405 String16 String16::stripWhiteSpace() const {
411 if (!length()) return String16(); 406 if (!length()) return String16();
412 407
413 size_t start = 0; 408 size_t start = 0;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // There should be room left, since one UChar hasn't been 509 // There should be room left, since one UChar hasn't been
515 // converted. 510 // converted.
516 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); 511 DCHECK((buffer + 3) <= (buffer + bufferVector.size()));
517 putUTF8Triple(buffer, *characters); 512 putUTF8Triple(buffer, *characters);
518 } 513 }
519 514
520 return std::string(bufferVector.data(), buffer - bufferVector.data()); 515 return std::string(bufferVector.data(), buffer - bufferVector.data());
521 } 516 }
522 517
523 } // namespace v8_inspector 518 } // namespace v8_inspector
OLDNEW
« 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