Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/V8StringUtil.cpp

Issue 2260233002: [DevTools] Migrate v8_inspector/public from String16 to String{View,Buffer}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: styling Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2750f0367c7ea369c110b32f9505bade2cb686f6 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);
@@ -277,4 +330,23 @@ std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
return nullptr;
}
+// static
+std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string)
+{
+ String16 owner = toString16(string);
+ return StringBufferImpl::adopt(owner);
+}
+
+// static
+std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string)
+{
+ return wrapUnique(new StringBufferImpl(string));
+}
+
+StringBufferImpl::StringBufferImpl(String16& string)
+{
+ m_owner.swap(string);
+ m_string = toStringView(m_owner);
+}
+
} // namespace v8_inspector

Powered by Google App Engine
This is Rietveld 408576698