Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::fromDoublePrecision3(double number) { |
| 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(3) << number; |
| 395 return String16(buffer); | 398 return String16(s.str().c_str()); |
| 396 } | 399 } |
| 397 | 400 |
| 398 // static | 401 // static |
| 399 String16 String16::fromDoublePrecision6(double number) { | 402 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.
| |
| 400 const size_t kBufferSize = 100; | 403 std::ostringstream s; |
| 401 char buffer[kBufferSize]; | 404 s.imbue(std::locale("C")); |
| 402 v8::base::OS::SNPrintF(buffer, kBufferSize, "%.6g", number); | 405 s << std::fixed << std::setprecision(6) << number; |
| 403 return String16(buffer); | 406 return String16(s.str().c_str()); |
| 404 } | 407 } |
| 405 | 408 |
| 406 int String16::toInteger(bool* ok) const { | 409 int String16::toInteger(bool* ok) const { |
| 407 return charactersToInteger(characters16(), length(), ok); | 410 return charactersToInteger(characters16(), length(), ok); |
| 408 } | 411 } |
| 409 | 412 |
| 410 String16 String16::stripWhiteSpace() const { | 413 String16 String16::stripWhiteSpace() const { |
| 411 if (!length()) return String16(); | 414 if (!length()) return String16(); |
| 412 | 415 |
| 413 size_t start = 0; | 416 size_t start = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 // There should be room left, since one UChar hasn't been | 517 // There should be room left, since one UChar hasn't been |
| 515 // converted. | 518 // converted. |
| 516 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); | 519 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); |
| 517 putUTF8Triple(buffer, *characters); | 520 putUTF8Triple(buffer, *characters); |
| 518 } | 521 } |
| 519 | 522 |
| 520 return std::string(bufferVector.data(), buffer - bufferVector.data()); | 523 return std::string(bufferVector.data(), buffer - bufferVector.data()); |
| 521 } | 524 } |
| 522 | 525 |
| 523 } // namespace v8_inspector | 526 } // namespace v8_inspector |
| OLD | NEW |