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> | |
| 12 #include <limits> | 11 #include <limits> |
| 13 #include <locale> | |
| 14 #include <sstream> | |
| 15 #include <string> | 12 #include <string> |
| 16 | 13 |
| 17 #include "src/base/platform/platform.h" | 14 #include "src/base/platform/platform.h" |
| 15 #include "src/conversions.h" | |
| 18 | 16 |
| 19 namespace v8_inspector { | 17 namespace v8_inspector { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 bool isASCII(UChar c) { return !(c & ~0x7F); } | 21 bool isASCII(UChar c) { return !(c & ~0x7F); } |
| 24 | 22 |
| 25 bool isSpaceOrNewLine(UChar c) { | 23 bool isSpaceOrNewLine(UChar c) { |
| 26 return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); | 24 return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); |
| 27 } | 25 } |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); | 358 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); |
| 361 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); | 359 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); |
| 362 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); | 360 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); |
| 363 } | 361 } |
| 364 | 362 |
| 365 } // namespace | 363 } // namespace |
| 366 | 364 |
| 367 // static | 365 // static |
| 368 String16 String16::fromInteger(int number) { | 366 String16 String16::fromInteger(int number) { |
| 369 const size_t kBufferSize = 50; | 367 const size_t kBufferSize = 50; |
| 370 char buffer[kBufferSize]; | 368 char arr[kBufferSize]; |
| 371 v8::base::OS::SNPrintF(buffer, kBufferSize, "%d", number); | 369 v8::internal::Vector<char> buffer(arr, arraysize(arr)); |
| 372 return String16(buffer); | 370 return String16(IntToCString(number, buffer)); |
| 373 } | 371 } |
| 374 | 372 |
| 375 // static | 373 // static |
| 376 String16 String16::fromInteger(size_t number) { | 374 String16 String16::fromInteger(size_t number) { |
| 375 return fromInteger(static_cast<int>(number)); | |
|
alph
2016/11/28 23:10:15
dead code below?
kozy
2016/11/28 23:12:45
good catch, removed this line.
| |
| 377 const size_t kBufferSize = 50; | 376 const size_t kBufferSize = 50; |
| 378 char buffer[kBufferSize]; | 377 char buffer[kBufferSize]; |
| 379 #if !defined(_WIN32) && !defined(_WIN64) | 378 #if !defined(_WIN32) && !defined(_WIN64) |
| 380 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); | 379 v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); |
| 381 #else | 380 #else |
| 382 v8::base::OS::SNPrintF(buffer, kBufferSize, "%Iu", number); | 381 v8::base::OS::SNPrintF(buffer, kBufferSize, "%Iu", number); |
| 383 #endif | 382 #endif |
| 384 return String16(buffer); | 383 return String16(buffer); |
| 385 } | 384 } |
| 386 | 385 |
| 387 // static | 386 // static |
| 388 String16 String16::fromDouble(double number) { | 387 String16 String16::fromDouble(double number) { |
| 389 std::ostringstream s; | 388 const size_t kBufferSize = 50; |
| 390 s.imbue(std::locale("C")); | 389 char arr[kBufferSize]; |
| 391 s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10) | 390 v8::internal::Vector<char> buffer(arr, arraysize(arr)); |
| 392 << number; | 391 return String16(DoubleToCString(number, buffer)); |
| 393 return String16(s.str().c_str()); | |
| 394 } | 392 } |
| 395 | 393 |
| 396 // static | 394 // static |
| 397 String16 String16::fromDouble(double number, int precision) { | 395 String16 String16::fromDouble(double number, int precision) { |
| 398 std::ostringstream s; | 396 std::unique_ptr<char[]> str( |
| 399 s.imbue(std::locale("C")); | 397 v8::internal::DoubleToPrecisionCString(number, precision)); |
| 400 s << std::fixed << std::setprecision(precision) << number; | 398 return String16(str.get()); |
| 401 return String16(s.str().c_str()); | |
| 402 } | 399 } |
| 403 | 400 |
| 404 int String16::toInteger(bool* ok) const { | 401 int String16::toInteger(bool* ok) const { |
| 405 return charactersToInteger(characters16(), length(), ok); | 402 return charactersToInteger(characters16(), length(), ok); |
| 406 } | 403 } |
| 407 | 404 |
| 408 String16 String16::stripWhiteSpace() const { | 405 String16 String16::stripWhiteSpace() const { |
| 409 if (!length()) return String16(); | 406 if (!length()) return String16(); |
| 410 | 407 |
| 411 size_t start = 0; | 408 size_t start = 0; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 // There should be room left, since one UChar hasn't been | 529 // There should be room left, since one UChar hasn't been |
| 533 // converted. | 530 // converted. |
| 534 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); | 531 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); |
| 535 putUTF8Triple(buffer, *characters); | 532 putUTF8Triple(buffer, *characters); |
| 536 } | 533 } |
| 537 | 534 |
| 538 return std::string(bufferVector.data(), buffer - bufferVector.data()); | 535 return std::string(bufferVector.data(), buffer - bufferVector.data()); |
| 539 } | 536 } |
| 540 | 537 |
| 541 } // namespace v8_inspector | 538 } // namespace v8_inspector |
| OLD | NEW |