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> |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 440 } |
441 | 441 |
442 void String16Builder::append(const UChar* characters, size_t length) { | 442 void String16Builder::append(const UChar* characters, size_t length) { |
443 m_buffer.insert(m_buffer.end(), characters, characters + length); | 443 m_buffer.insert(m_buffer.end(), characters, characters + length); |
444 } | 444 } |
445 | 445 |
446 void String16Builder::append(const char* characters, size_t length) { | 446 void String16Builder::append(const char* characters, size_t length) { |
447 m_buffer.insert(m_buffer.end(), characters, characters + length); | 447 m_buffer.insert(m_buffer.end(), characters, characters + length); |
448 } | 448 } |
449 | 449 |
| 450 void String16Builder::appendNumber(int number) { |
| 451 const int kBufferSize = 11; |
| 452 char buffer[kBufferSize]; |
| 453 int chars = v8::base::OS::SNPrintF(buffer, kBufferSize, "%d", number); |
| 454 DCHECK_GT(kBufferSize, chars); |
| 455 m_buffer.insert(m_buffer.end(), buffer, buffer + chars); |
| 456 } |
| 457 |
| 458 void String16Builder::appendNumber(size_t number) { |
| 459 const int kBufferSize = 20; |
| 460 char buffer[kBufferSize]; |
| 461 #if !defined(_WIN32) && !defined(_WIN64) |
| 462 int chars = v8::base::OS::SNPrintF(buffer, kBufferSize, "%zu", number); |
| 463 #else |
| 464 int chars = v8::base::OS::SNPrintF(buffer, kBufferSize, "%Iu", number); |
| 465 #endif |
| 466 DCHECK_GT(kBufferSize, chars); |
| 467 m_buffer.insert(m_buffer.end(), buffer, buffer + chars); |
| 468 } |
| 469 |
450 String16 String16Builder::toString() { | 470 String16 String16Builder::toString() { |
451 return String16(m_buffer.data(), m_buffer.size()); | 471 return String16(m_buffer.data(), m_buffer.size()); |
452 } | 472 } |
453 | 473 |
454 void String16Builder::reserveCapacity(size_t capacity) { | 474 void String16Builder::reserveCapacity(size_t capacity) { |
455 m_buffer.reserve(capacity); | 475 m_buffer.reserve(capacity); |
456 } | 476 } |
457 | 477 |
458 String16 String16::fromUTF8(const char* stringStart, size_t length) { | 478 String16 String16::fromUTF8(const char* stringStart, size_t length) { |
459 if (!stringStart || !length) return String16(); | 479 if (!stringStart || !length) return String16(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // There should be room left, since one UChar hasn't been | 533 // There should be room left, since one UChar hasn't been |
514 // converted. | 534 // converted. |
515 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); | 535 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); |
516 putUTF8Triple(buffer, *characters); | 536 putUTF8Triple(buffer, *characters); |
517 } | 537 } |
518 | 538 |
519 return std::string(bufferVector.data(), buffer - bufferVector.data()); | 539 return std::string(bufferVector.data(), buffer - bufferVector.data()); |
520 } | 540 } |
521 | 541 |
522 } // namespace v8_inspector | 542 } // namespace v8_inspector |
OLD | NEW |