| 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> | |
| 12 #include <limits> | 11 #include <limits> |
| 13 #include <locale> | 12 #include <locale> |
| 14 #include <sstream> | |
| 15 #include <string> | 13 #include <string> |
| 16 | 14 |
| 17 #include "src/base/platform/platform.h" | 15 #include "src/base/platform/platform.h" |
| 18 #include "src/inspector/protocol-platform.h" | 16 #include "src/inspector/protocol-platform.h" |
| 19 | 17 |
| 20 namespace v8_inspector { | 18 namespace v8_inspector { |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 bool isASCII(UChar c) { return !(c & ~0x7F); } | 22 bool isASCII(UChar c) { return !(c & ~0x7F); } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // static | 374 // static |
| 377 String16 String16::fromInteger(size_t number) { | 375 String16 String16::fromInteger(size_t number) { |
| 378 const size_t kBufferSize = 50; | 376 const size_t kBufferSize = 50; |
| 379 char buffer[kBufferSize]; | 377 char buffer[kBufferSize]; |
| 380 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); | 378 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); |
| 381 return String16(buffer); | 379 return String16(buffer); |
| 382 } | 380 } |
| 383 | 381 |
| 384 // static | 382 // static |
| 385 String16 String16::fromDouble(double number) { | 383 String16 String16::fromDouble(double number) { |
| 386 std::ostringstream s; | 384 const size_t kBufferSize = 100; |
| 387 s.imbue(std::locale("C")); | 385 char buffer[kBufferSize]; |
| 388 s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10) | 386 v8::base::OS::SNPrintF(buffer, kBufferSize, "%f", number); |
| 389 << number; | 387 return String16(buffer); |
| 390 return String16(s.str().c_str()); | |
| 391 } | 388 } |
| 392 | 389 |
| 393 // static | 390 // static |
| 394 String16 String16::fromDouble(double number, int precision) { | 391 String16 String16::fromDoublePrecision3(double number) { |
| 395 std::ostringstream s; | 392 const size_t kBufferSize = 100; |
| 396 s.imbue(std::locale("C")); | 393 char buffer[kBufferSize]; |
| 397 s << std::fixed << std::setprecision(precision) << number; | 394 v8::base::OS::SNPrintF(buffer, kBufferSize, "%.3g", number); |
| 398 return String16(s.str().c_str()); | 395 return String16(buffer); |
| 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); |
| 399 } | 404 } |
| 400 | 405 |
| 401 int String16::toInteger(bool* ok) const { | 406 int String16::toInteger(bool* ok) const { |
| 402 return charactersToInteger(characters16(), length(), ok); | 407 return charactersToInteger(characters16(), length(), ok); |
| 403 } | 408 } |
| 404 | 409 |
| 405 String16 String16::stripWhiteSpace() const { | 410 String16 String16::stripWhiteSpace() const { |
| 406 if (!length()) return String16(); | 411 if (!length()) return String16(); |
| 407 | 412 |
| 408 size_t start = 0; | 413 size_t start = 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // There should be room left, since one UChar hasn't been | 514 // There should be room left, since one UChar hasn't been |
| 510 // converted. | 515 // converted. |
| 511 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); | 516 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); |
| 512 putUTF8Triple(buffer, *characters); | 517 putUTF8Triple(buffer, *characters); |
| 513 } | 518 } |
| 514 | 519 |
| 515 return std::string(bufferVector.data(), buffer - bufferVector.data()); | 520 return std::string(bufferVector.data(), buffer - bufferVector.data()); |
| 516 } | 521 } |
| 517 | 522 |
| 518 } // namespace v8_inspector | 523 } // namespace v8_inspector |
| OLD | NEW |