| 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/v8_inspector/V8StringUtil.h" | 5 #include "platform/v8_inspector/V8StringUtil.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 9 #include "platform/v8_inspector/V8Regex.h" | 9 #include "platform/v8_inspector/V8Regex.h" |
| 10 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" | 10 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 if (text.isEmpty()) | 118 if (text.isEmpty()) |
| 119 return result; | 119 return result; |
| 120 | 120 |
| 121 OwnPtr<protocol::Vector<unsigned>> endings(lineEndings(text)); | 121 OwnPtr<protocol::Vector<unsigned>> endings(lineEndings(text)); |
| 122 unsigned size = endings->size(); | 122 unsigned size = endings->size(); |
| 123 unsigned start = 0; | 123 unsigned start = 0; |
| 124 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { | 124 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { |
| 125 unsigned lineEnd = endings->at(lineNumber); | 125 unsigned lineEnd = endings->at(lineNumber); |
| 126 String16 line = text.substring(start, lineEnd - start); | 126 String16 line = text.substring(start, lineEnd - start); |
| 127 if (line.endsWith('\r')) | 127 if (line.endsWith('\r')) |
| 128 line = line.left(line.length() - 1); | 128 line = line.substring(0, line.length() - 1); |
| 129 | 129 |
| 130 int matchLength; | 130 int matchLength; |
| 131 if (regex.match(line, 0, &matchLength) != -1) | 131 if (regex.match(line, 0, &matchLength) != -1) |
| 132 result.append(std::pair<int, String16>(lineNumber, line)); | 132 result.append(std::pair<int, String16>(lineNumber, line)); |
| 133 | 133 |
| 134 start = lineEnd + 1; | 134 start = lineEnd + 1; |
| 135 } | 135 } |
| 136 return result; | 136 return result; |
| 137 } | 137 } |
| 138 | 138 |
| 139 PassOwnPtr<protocol::Debugger::SearchMatch> buildObjectForSearchMatch(int lineNu
mber, const String16& lineContent) | 139 PassOwnPtr<protocol::Debugger::SearchMatch> buildObjectForSearchMatch(int lineNu
mber, const String16& lineContent) |
| 140 { | 140 { |
| 141 return protocol::Debugger::SearchMatch::create() | 141 return protocol::Debugger::SearchMatch::create() |
| 142 .setLineNumber(lineNumber) | 142 .setLineNumber(lineNumber) |
| 143 .setLineContent(lineContent) | 143 .setLineContent(lineContent) |
| 144 .build(); | 144 .build(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 PassOwnPtr<V8Regex> createSearchRegex(V8DebuggerImpl* debugger, const String16&
query, bool caseSensitive, bool isRegex) | 147 PassOwnPtr<V8Regex> createSearchRegex(V8DebuggerImpl* debugger, const String16&
query, bool caseSensitive, bool isRegex) |
| 148 { | 148 { |
| 149 String16 regexSource = isRegex ? query : createSearchRegexSource(query); | 149 String16 regexSource = isRegex ? query : createSearchRegexSource(query); |
| 150 return adoptPtr(new V8Regex(debugger, regexSource, caseSensitive)); | 150 return adoptPtr(new V8Regex(debugger, regexSource, caseSensitive)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) | 155 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) |
| 156 { | 156 { |
| 157 if (string.isNull()) | 157 if (string.isEmpty()) |
| 158 return v8::String::Empty(isolate); | 158 return v8::String::Empty(isolate); |
| 159 if (string.is8Bit()) | |
| 160 return v8::String::NewFromOneByte(isolate, string.characters8(), v8::New
StringType::kNormal, string.length()).ToLocalChecked(); | |
| 161 return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>
(string.characters16()), v8::NewStringType::kNormal, string.length()).ToLocalChe
cked(); | 159 return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>
(string.characters16()), v8::NewStringType::kNormal, string.length()).ToLocalChe
cked(); |
| 162 } | 160 } |
| 163 | 161 |
| 164 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, const String1
6& string) | 162 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, const String1
6& string) |
| 165 { | 163 { |
| 166 if (string.isNull()) | 164 if (string.isEmpty()) |
| 167 return v8::String::Empty(isolate); | 165 return v8::String::Empty(isolate); |
| 168 if (string.is8Bit()) | |
| 169 return v8::String::NewFromOneByte(isolate, string.characters8(), v8::New
StringType::kInternalized, string.length()).ToLocalChecked(); | |
| 170 return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>
(string.characters16()), v8::NewStringType::kInternalized, string.length()).ToLo
calChecked(); | 166 return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>
(string.characters16()), v8::NewStringType::kInternalized, string.length()).ToLo
calChecked(); |
| 171 } | 167 } |
| 172 | 168 |
| 173 String16 toProtocolString(v8::Local<v8::String> value) | 169 String16 toProtocolString(v8::Local<v8::String> value) |
| 174 { | 170 { |
| 175 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) | 171 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
| 176 return String16(); | 172 return String16(); |
| 177 UChar* buffer; | 173 UChar* buffer; |
| 178 String16 result = String16::createUninitialized(value->Length(), buffer); | 174 String16 result = String16::createUninitialized(value->Length(), buffer); |
| 179 value->Write(reinterpret_cast<uint16_t*>(buffer), 0, value->Length()); | 175 value->Write(reinterpret_cast<uint16_t*>(buffer), 0, value->Length()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 return nullptr; | 271 return nullptr; |
| 276 jsonObject->setValue(toProtocolString(propertyName), propertyValue.r
elease()); | 272 jsonObject->setValue(toProtocolString(propertyName), propertyValue.r
elease()); |
| 277 } | 273 } |
| 278 return jsonObject.release(); | 274 return jsonObject.release(); |
| 279 } | 275 } |
| 280 ASSERT_NOT_REACHED(); | 276 ASSERT_NOT_REACHED(); |
| 281 return nullptr; | 277 return nullptr; |
| 282 } | 278 } |
| 283 | 279 |
| 284 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |