| 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/v8_inspector/V8DebuggerImpl.h" | 7 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 8 #include "platform/v8_inspector/V8Regex.h" | 8 #include "platform/v8_inspector/V8Regex.h" |
| 9 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" | 9 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" |
| 10 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 for (unsigned i = 0; i < text.length(); i++) { | 87 for (unsigned i = 0; i < text.length(); i++) { |
| 88 if (specials.find(text[i]) != kNotFound) | 88 if (specials.find(text[i]) != kNotFound) |
| 89 result.append('\\'); | 89 result.append('\\'); |
| 90 result.append(text[i]); | 90 result.append(text[i]); |
| 91 } | 91 } |
| 92 | 92 |
| 93 return result.toString(); | 93 return result.toString(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 PassOwnPtr<Vector<unsigned>> lineEndings(const String& text) | 96 PassOwnPtr<protocol::Vector<unsigned>> lineEndings(const String& text) |
| 97 { | 97 { |
| 98 OwnPtr<Vector<unsigned>> result(adoptPtr(new Vector<unsigned>())); | 98 OwnPtr<protocol::Vector<unsigned>> result(adoptPtr(new protocol::Vector<unsi
gned>())); |
| 99 | 99 |
| 100 unsigned start = 0; | 100 unsigned start = 0; |
| 101 while (start < text.length()) { | 101 while (start < text.length()) { |
| 102 size_t lineEnd = text.find('\n', start); | 102 size_t lineEnd = text.find('\n', start); |
| 103 if (lineEnd == kNotFound) | 103 if (lineEnd == kNotFound) |
| 104 break; | 104 break; |
| 105 | 105 |
| 106 result->append(static_cast<unsigned>(lineEnd)); | 106 result->append(static_cast<unsigned>(lineEnd)); |
| 107 start = lineEnd + 1; | 107 start = lineEnd + 1; |
| 108 } | 108 } |
| 109 result->append(text.length()); | 109 result->append(text.length()); |
| 110 | 110 |
| 111 return result.release(); | 111 return result.release(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 Vector<std::pair<int, String>> scriptRegexpMatchesByLines(const V8Regex& regex,
const String& text) | 114 protocol::Vector<std::pair<int, String>> scriptRegexpMatchesByLines(const V8Rege
x& regex, const String& text) |
| 115 { | 115 { |
| 116 Vector<std::pair<int, String>> result; | 116 protocol::Vector<std::pair<int, String>> result; |
| 117 if (text.isEmpty()) | 117 if (text.isEmpty()) |
| 118 return result; | 118 return result; |
| 119 | 119 |
| 120 OwnPtr<Vector<unsigned>> endings(lineEndings(text)); | 120 OwnPtr<protocol::Vector<unsigned>> endings(lineEndings(text)); |
| 121 unsigned size = endings->size(); | 121 unsigned size = endings->size(); |
| 122 unsigned start = 0; | 122 unsigned start = 0; |
| 123 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { | 123 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { |
| 124 unsigned lineEnd = endings->at(lineNumber); | 124 unsigned lineEnd = endings->at(lineNumber); |
| 125 String line = text.substring(start, lineEnd - start); | 125 String line = text.substring(start, lineEnd - start); |
| 126 if (line.endsWith('\r')) | 126 if (line.endsWith('\r')) |
| 127 line = line.left(line.length() - 1); | 127 line = line.left(line.length() - 1); |
| 128 | 128 |
| 129 int matchLength; | 129 int matchLength; |
| 130 if (regex.match(line, 0, &matchLength) != -1) | 130 if (regex.match(line, 0, &matchLength) != -1) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 String findSourceMapURL(const String& content, bool multiline, bool* deprecated) | 188 String findSourceMapURL(const String& content, bool multiline, bool* deprecated) |
| 189 { | 189 { |
| 190 return findMagicComment(content, "sourceMappingURL", multiline, deprecated); | 190 return findMagicComment(content, "sourceMappingURL", multiline, deprecated); |
| 191 } | 191 } |
| 192 | 192 |
| 193 PassOwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines
(V8Debugger* debugger, const String& text, const String& query, const bool caseS
ensitive, const bool isRegex) | 193 PassOwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines
(V8Debugger* debugger, const String& text, const String& query, const bool caseS
ensitive, const bool isRegex) |
| 194 { | 194 { |
| 195 OwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> result = protocol::
Array<protocol::Debugger::SearchMatch>::create(); | 195 OwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> result = protocol::
Array<protocol::Debugger::SearchMatch>::create(); |
| 196 OwnPtr<V8Regex> regex = createSearchRegex(static_cast<V8DebuggerImpl*>(debug
ger), query, caseSensitive, isRegex); | 196 OwnPtr<V8Regex> regex = createSearchRegex(static_cast<V8DebuggerImpl*>(debug
ger), query, caseSensitive, isRegex); |
| 197 Vector<std::pair<int, String>> matches = scriptRegexpMatchesByLines(*regex.g
et(), text); | 197 protocol::Vector<std::pair<int, String>> matches = scriptRegexpMatchesByLine
s(*regex.get(), text); |
| 198 | 198 |
| 199 for (const auto& match : matches) | 199 for (const auto& match : matches) |
| 200 result->addItem(buildObjectForSearchMatch(match.first, match.second)); | 200 result->addItem(buildObjectForSearchMatch(match.first, match.second)); |
| 201 | 201 |
| 202 return result.release(); | 202 return result.release(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace V8ContentSearchUtil | 205 } // namespace V8ContentSearchUtil |
| 206 | 206 |
| 207 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |