| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/inspector_protocol/String16WTF.h" | 5 #include "platform/inspector_protocol/String16WTF.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 namespace protocol { | 8 namespace protocol { |
| 9 | 9 |
| 10 String16::String16(const String16& other) : m_impl(other.m_impl) { } | 10 String16::String16(const String16& other) : m_impl(other.m_impl) { } |
| 11 | 11 |
| 12 String16::String16(const UChar* u, unsigned length) : m_impl(u, length) { } | 12 String16::String16(const UChar* u, unsigned length) : m_impl(u, length) { } |
| 13 | 13 |
| 14 String16::String16(const char* characters) : String16(characters, strlen(charact
ers)) { } | 14 String16::String16(const char* characters) : String16(characters, strlen(charact
ers)) { } |
| 15 | 15 |
| 16 String16::String16(const WTF::String& other) | 16 String16::String16(const WTF::String& other) |
| 17 { | 17 { |
| 18 if (other.isNull()) | 18 if (other.isNull()) |
| 19 return; | 19 return; |
| 20 if (!other.is8Bit()) { | 20 m_impl = other; |
| 21 m_impl = other; | 21 m_impl.ensure16Bit(); |
| 22 return; | |
| 23 } | |
| 24 | |
| 25 UChar* data; | |
| 26 const LChar* characters = other.characters8(); | |
| 27 size_t length = other.length(); | |
| 28 m_impl = String::createUninitialized(length, data); | |
| 29 for (size_t i = 0; i < length; ++i) | |
| 30 data[i] = characters[i]; | |
| 31 } | 22 } |
| 32 | 23 |
| 33 String16::String16(const char* characters, size_t length) | 24 String16::String16(const char* characters, size_t length) |
| 34 { | 25 { |
| 35 UChar* data; | 26 UChar* data; |
| 36 m_impl = String::createUninitialized(length, data); | 27 m_impl = String::createUninitialized(length, data); |
| 37 for (size_t i = 0; i < length; ++i) | 28 for (size_t i = 0; i < length; ++i) |
| 38 data[i] = characters[i]; | 29 data[i] = characters[i]; |
| 39 } | 30 } |
| 40 | 31 |
| 41 String16 String16::createUninitialized(unsigned length, UChar*& data) | |
| 42 { | |
| 43 return String::createUninitialized(length, data); | |
| 44 } | |
| 45 | |
| 46 } // namespace protocol | 32 } // namespace protocol |
| 47 } // namespace blink | 33 } // namespace blink |
| OLD | NEW |