Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/V8InspectorString.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/V8InspectorString.cpp b/third_party/WebKit/Source/core/inspector/V8InspectorString.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b82c9e82f7dc81813978e4433cf8d053139990e |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/inspector/V8InspectorString.cpp |
| @@ -0,0 +1,46 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/inspector/V8InspectorString.h" |
| + |
| +namespace blink { |
| + |
| +v8_inspector::StringView toV8InspectorStringView(const StringView& string) |
| +{ |
| + if (string.isNull()) |
| + return v8_inspector::StringView(); |
| + if (string.is8Bit()) |
| + return v8_inspector::StringView(reinterpret_cast<const uint8_t*>(string.characters8()), string.length()); |
| + return v8_inspector::StringView(reinterpret_cast<const uint16_t*>(string.characters16()), string.length()); |
| +} |
| + |
| +std::unique_ptr<v8_inspector::StringBuffer> toV8InspectorStringBuffer(const StringView& string) |
| +{ |
| + return v8_inspector::StringBuffer::create(toV8InspectorStringView(string)); |
| +} |
| + |
| +String toCoreString(const v8_inspector::StringView& string) |
| +{ |
| + if (string.is8Bit()) { |
| + if (!string.characters8()) |
|
esprehn
2016/08/23 17:35:39
the string constructor does this for you.
|
| + return String(); |
| + if (!string.length()) |
| + return emptyString(); |
|
esprehn
2016/08/23 17:35:39
ditto
|
| + return String(reinterpret_cast<const LChar*>(string.characters8()), string.length()); |
| + } |
| + if (!string.characters16()) |
| + return String(); |
|
esprehn
2016/08/23 17:35:39
ditto, you don't need to null check or empty check
dgozman
2016/08/24 00:45:00
Done.
|
| + if (!string.length()) |
| + return emptyString(); |
| + return String(reinterpret_cast<const UChar*>(string.characters16()), string.length()); |
| +} |
| + |
| +String toCoreString(std::unique_ptr<v8_inspector::StringBuffer> buffer) |
| +{ |
| + if (!buffer) |
| + return String(); |
| + return toCoreString(buffer->string()); |
| +} |
| + |
| +} // namespace blink |