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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // Helper to write a three-byte UTF-8 code point to the buffer, caller must | 355 // Helper to write a three-byte UTF-8 code point to the buffer, caller must |
356 // check room is available. | 356 // check room is available. |
357 static inline void putUTF8Triple(char*& buffer, UChar ch) { | 357 static inline void putUTF8Triple(char*& buffer, UChar ch) { |
358 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); | 358 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); |
359 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); | 359 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); |
360 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); | 360 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); |
361 } | 361 } |
362 | 362 |
363 } // namespace | 363 } // namespace |
364 | 364 |
| 365 String16::String16() {} |
| 366 |
| 367 String16::String16(const String16& other) |
| 368 : m_impl(other.m_impl), hash_code(other.hash_code) {} |
| 369 |
| 370 String16::String16(String16&& other) |
| 371 : m_impl(std::move(other.m_impl)), hash_code(other.hash_code) {} |
| 372 |
| 373 String16::String16(const UChar* characters, size_t size) |
| 374 : m_impl(characters, size) {} |
| 375 |
| 376 String16::String16(const UChar* characters) : m_impl(characters) {} |
| 377 |
| 378 String16::String16(const char* characters) |
| 379 : String16(characters, std::strlen(characters)) {} |
| 380 |
| 381 String16::String16(const char* characters, size_t size) { |
| 382 m_impl.resize(size); |
| 383 for (size_t i = 0; i < size; ++i) m_impl[i] = characters[i]; |
| 384 } |
| 385 |
| 386 String16::String16(const std::basic_string<UChar>& impl) : m_impl(impl) {} |
| 387 |
| 388 String16& String16::operator=(const String16& other) { |
| 389 m_impl = other.m_impl; |
| 390 hash_code = other.hash_code; |
| 391 return *this; |
| 392 } |
| 393 |
| 394 String16& String16::operator=(String16&& other) { |
| 395 m_impl = std::move(other.m_impl); |
| 396 hash_code = other.hash_code; |
| 397 return *this; |
| 398 } |
| 399 |
365 // static | 400 // static |
366 String16 String16::fromInteger(int number) { | 401 String16 String16::fromInteger(int number) { |
367 char arr[50]; | 402 char arr[50]; |
368 v8::internal::Vector<char> buffer(arr, arraysize(arr)); | 403 v8::internal::Vector<char> buffer(arr, arraysize(arr)); |
369 return String16(IntToCString(number, buffer)); | 404 return String16(IntToCString(number, buffer)); |
370 } | 405 } |
371 | 406 |
372 // static | 407 // static |
373 String16 String16::fromInteger(size_t number) { | 408 String16 String16::fromInteger(size_t number) { |
374 const size_t kBufferSize = 50; | 409 const size_t kBufferSize = 50; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // There should be room left, since one UChar hasn't been | 561 // There should be room left, since one UChar hasn't been |
527 // converted. | 562 // converted. |
528 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); | 563 DCHECK((buffer + 3) <= (buffer + bufferVector.size())); |
529 putUTF8Triple(buffer, *characters); | 564 putUTF8Triple(buffer, *characters); |
530 } | 565 } |
531 | 566 |
532 return std::string(bufferVector.data(), buffer - bufferVector.data()); | 567 return std::string(bufferVector.data(), buffer - bufferVector.data()); |
533 } | 568 } |
534 | 569 |
535 } // namespace v8_inspector | 570 } // namespace v8_inspector |
OLD | NEW |