| Index: third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp
|
| diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp
|
| index d078da6a0e3b75919570a9340a003ad1be7b054f..6c0b2bf0f22ad28bbf1a09ec5d856ef2a3ae9b62 100644
|
| --- a/third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp
|
| +++ b/third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "platform/v8_inspector/V8StringUtil.h"
|
|
|
| +#include "platform/inspector_protocol/InspectorProtocol.h"
|
| #include "platform/v8_inspector/V8InspectorImpl.h"
|
| #include "platform/v8_inspector/V8InspectorSessionImpl.h"
|
| #include "platform/v8_inspector/V8Regex.h"
|
| @@ -167,6 +168,15 @@ v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, const char* s
|
| return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized).ToLocalChecked();
|
| }
|
|
|
| +v8::Local<v8::String> toV8String(v8::Isolate* isolate, const StringView& string)
|
| +{
|
| + if (!string.length())
|
| + return v8::String::Empty(isolate);
|
| + if (string.is8Bit())
|
| + return v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(string.characters8()), v8::NewStringType::kNormal, string.length()).ToLocalChecked();
|
| + return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(string.characters16()), v8::NewStringType::kNormal, string.length()).ToLocalChecked();
|
| +}
|
| +
|
| String16 toProtocolString(v8::Local<v8::String> value)
|
| {
|
| if (value.IsEmpty() || value->IsNull() || value->IsUndefined())
|
| @@ -183,6 +193,49 @@ String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value> value)
|
| return toProtocolString(value.As<v8::String>());
|
| }
|
|
|
| +String16 toString16(const StringView& string)
|
| +{
|
| + if (!string.length())
|
| + return String16();
|
| + if (string.is8Bit())
|
| + return String16(reinterpret_cast<const char*>(string.characters8()), string.length());
|
| + return String16(reinterpret_cast<const UChar*>(string.characters16()), string.length());
|
| +}
|
| +
|
| +StringView toStringView(const String16& string)
|
| +{
|
| + if (string.isEmpty())
|
| + return StringView();
|
| + return StringView(reinterpret_cast<const uint16_t*>(string.characters16()), string.length());
|
| +}
|
| +
|
| +bool stringViewStartsWith(const StringView& string, const char* prefix)
|
| +{
|
| + if (!string.length())
|
| + return !(*prefix);
|
| + if (string.is8Bit()) {
|
| + for (size_t i = 0, j = 0; prefix[j] && i < string.length(); ++i, ++j) {
|
| + if (string.characters8()[i] != prefix[j])
|
| + return false;
|
| + }
|
| + } else {
|
| + for (size_t i = 0, j = 0; prefix[j] && i < string.length(); ++i, ++j) {
|
| + if (string.characters16()[i] != prefix[j])
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +std::unique_ptr<protocol::Value> parseJSON(const StringView& string)
|
| +{
|
| + if (!string.length())
|
| + return nullptr;
|
| + if (string.is8Bit())
|
| + return blink::protocol::parseJSON(string.characters8(), string.length());
|
| + return blink::protocol::parseJSON(string.characters16(), string.length());
|
| +}
|
| +
|
| std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> searchInTextByLinesImpl(V8InspectorSession* session, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex)
|
| {
|
| std::unique_ptr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSessionImpl*>(session)->inspector(), query, caseSensitive, isRegex);
|
|
|