| 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/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 10 #include "platform/v8_inspector/V8Regex.h" | 10 #include "platform/v8_inspector/V8Regex.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 for (unsigned i = 0; i < text.length(); i++) { | 89 for (unsigned i = 0; i < text.length(); i++) { |
| 90 if (specials.find(text[i]) != kNotFound) | 90 if (specials.find(text[i]) != kNotFound) |
| 91 result.append('\\'); | 91 result.append('\\'); |
| 92 result.append(text[i]); | 92 result.append(text[i]); |
| 93 } | 93 } |
| 94 | 94 |
| 95 return result.toString(); | 95 return result.toString(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::unique_ptr<protocol::Vector<unsigned>> lineEndings(const String16& text) | 98 std::unique_ptr<std::vector<unsigned>> lineEndings(const String16& text) |
| 99 { | 99 { |
| 100 std::unique_ptr<protocol::Vector<unsigned>> result(new protocol::Vector<unsi
gned>()); | 100 std::unique_ptr<std::vector<unsigned>> result(new std::vector<unsigned>()); |
| 101 | 101 |
| 102 unsigned start = 0; | 102 unsigned start = 0; |
| 103 while (start < text.length()) { | 103 while (start < text.length()) { |
| 104 size_t lineEnd = text.find('\n', start); | 104 size_t lineEnd = text.find('\n', start); |
| 105 if (lineEnd == kNotFound) | 105 if (lineEnd == kNotFound) |
| 106 break; | 106 break; |
| 107 | 107 |
| 108 result->append(static_cast<unsigned>(lineEnd)); | 108 result->push_back(static_cast<unsigned>(lineEnd)); |
| 109 start = lineEnd + 1; | 109 start = lineEnd + 1; |
| 110 } | 110 } |
| 111 result->append(text.length()); | 111 result->push_back(text.length()); |
| 112 | 112 |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 | 115 |
| 116 protocol::Vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Re
gex& regex, const String16& text) | 116 std::vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Regex&
regex, const String16& text) |
| 117 { | 117 { |
| 118 protocol::Vector<std::pair<int, String16>> result; | 118 std::vector<std::pair<int, String16>> result; |
| 119 if (text.isEmpty()) | 119 if (text.isEmpty()) |
| 120 return result; | 120 return result; |
| 121 | 121 |
| 122 std::unique_ptr<protocol::Vector<unsigned>> endings(lineEndings(text)); | 122 std::unique_ptr<std::vector<unsigned>> endings(lineEndings(text)); |
| 123 unsigned size = endings->size(); | 123 unsigned size = endings->size(); |
| 124 unsigned start = 0; | 124 unsigned start = 0; |
| 125 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { | 125 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { |
| 126 unsigned lineEnd = endings->at(lineNumber); | 126 unsigned lineEnd = endings->at(lineNumber); |
| 127 String16 line = text.substring(start, lineEnd - start); | 127 String16 line = text.substring(start, lineEnd - start); |
| 128 if (line.endsWith('\r')) | 128 if (line.endsWith('\r')) |
| 129 line = line.substring(0, line.length() - 1); | 129 line = line.substring(0, line.length() - 1); |
| 130 | 130 |
| 131 int matchLength; | 131 int matchLength; |
| 132 if (regex.match(line, 0, &matchLength) != -1) | 132 if (regex.match(line, 0, &matchLength) != -1) |
| 133 result.append(std::pair<int, String16>(lineNumber, line)); | 133 result.push_back(std::pair<int, String16>(lineNumber, line)); |
| 134 | 134 |
| 135 start = lineEnd + 1; | 135 start = lineEnd + 1; |
| 136 } | 136 } |
| 137 return result; | 137 return result; |
| 138 } | 138 } |
| 139 | 139 |
| 140 std::unique_ptr<protocol::Debugger::SearchMatch> buildObjectForSearchMatch(int l
ineNumber, const String16& lineContent) | 140 std::unique_ptr<protocol::Debugger::SearchMatch> buildObjectForSearchMatch(int l
ineNumber, const String16& lineContent) |
| 141 { | 141 { |
| 142 return protocol::Debugger::SearchMatch::create() | 142 return protocol::Debugger::SearchMatch::create() |
| 143 .setLineNumber(lineNumber) | 143 .setLineNumber(lineNumber) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 String16 findSourceMapURL(const String16& content, bool multiline, bool* depreca
ted) | 193 String16 findSourceMapURL(const String16& content, bool multiline, bool* depreca
ted) |
| 194 { | 194 { |
| 195 return findMagicComment(content, "sourceMappingURL", multiline, deprecated); | 195 return findMagicComment(content, "sourceMappingURL", multiline, deprecated); |
| 196 } | 196 } |
| 197 | 197 |
| 198 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextBy
Lines(V8InspectorSession* session, const String16& text, const String16& query,
const bool caseSensitive, const bool isRegex) | 198 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextBy
Lines(V8InspectorSession* session, const String16& text, const String16& query,
const bool caseSensitive, const bool isRegex) |
| 199 { | 199 { |
| 200 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> result = p
rotocol::Array<protocol::Debugger::SearchMatch>::create(); | 200 std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> result = p
rotocol::Array<protocol::Debugger::SearchMatch>::create(); |
| 201 std::unique_ptr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSe
ssionImpl*>(session)->debugger(), query, caseSensitive, isRegex); | 201 std::unique_ptr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSe
ssionImpl*>(session)->debugger(), query, caseSensitive, isRegex); |
| 202 protocol::Vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLi
nes(*regex.get(), text); | 202 std::vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLines(*
regex.get(), text); |
| 203 | 203 |
| 204 for (const auto& match : matches) | 204 for (const auto& match : matches) |
| 205 result->addItem(buildObjectForSearchMatch(match.first, match.second)); | 205 result->addItem(buildObjectForSearchMatch(match.first, match.second)); |
| 206 | 206 |
| 207 return result; | 207 return result; |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace V8ContentSearchUtil | 210 } // namespace V8ContentSearchUtil |
| 211 | 211 |
| 212 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
v8::Local<v8::Value> value, int maxDepth) | 212 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
v8::Local<v8::Value> value, int maxDepth) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return nullptr; | 271 return nullptr; |
| 272 jsonObject->setValue(toProtocolString(propertyName), std::move(prope
rtyValue)); | 272 jsonObject->setValue(toProtocolString(propertyName), std::move(prope
rtyValue)); |
| 273 } | 273 } |
| 274 return std::move(jsonObject); | 274 return std::move(jsonObject); |
| 275 } | 275 } |
| 276 NOTREACHED(); | 276 NOTREACHED(); |
| 277 return nullptr; | 277 return nullptr; |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |