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/V8InspectorImpl.h" | 8 #include "platform/v8_inspector/V8InspectorImpl.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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 DCHECK(equalSignPos); | 61 DCHECK(equalSignPos); |
62 DCHECK(!multiline || closingCommentPos); | 62 DCHECK(!multiline || closingCommentPos); |
63 size_t urlPos = equalSignPos + 1; | 63 size_t urlPos = equalSignPos + 1; |
64 String16 match = multiline | 64 String16 match = multiline |
65 ? content.substring(urlPos, closingCommentPos - urlPos) | 65 ? content.substring(urlPos, closingCommentPos - urlPos) |
66 : content.substring(urlPos); | 66 : content.substring(urlPos); |
67 | 67 |
68 size_t newLine = match.find("\n"); | 68 size_t newLine = match.find("\n"); |
69 if (newLine != kNotFound) | 69 if (newLine != kNotFound) |
70 match = match.substring(0, newLine); | 70 match = match.substring(0, newLine); |
71 match = match.stripWhiteSpace(); | 71 match = protocol::string16StripWhiteSpace(match); |
72 | 72 |
73 String16 disallowedChars("\"' \t"); | |
74 for (unsigned i = 0; i < match.length(); ++i) { | 73 for (unsigned i = 0; i < match.length(); ++i) { |
75 if (disallowedChars.find(match[i]) != kNotFound) | 74 UChar c = match[i]; |
75 if (c == '"' || c == '\'' || c == ' ' || c == '\t') | |
76 return ""; | 76 return ""; |
77 } | 77 } |
78 | 78 |
79 return match; | 79 return match; |
80 } | 80 } |
81 | 81 |
82 String16 createSearchRegexSource(const String16& text) | 82 String16 createSearchRegexSource(const String16& text) |
83 { | 83 { |
84 String16Builder result; | 84 String16Builder result; |
85 String16 specials("[](){}+-*.,?\\^$|"); | 85 String16 specials("[](){}+-*.,?\\^$|"); |
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 UChar c = text[i]; |
89 if (c == '[' || c == ']' || c == '(' || c == ')' || c == '{' || c == '}' | |
90 || c == '+' || c == '-' || c == '*' || c == '.' || c == ',' || c == '?' | |
91 || c == '\\' || c == '^' || c == '$' || c == '|') { | |
89 result.append('\\'); | 92 result.append('\\'); |
93 } | |
90 result.append(text[i]); | 94 result.append(text[i]); |
91 } | 95 } |
92 | 96 |
93 return result.toString(); | 97 return result.toString(); |
94 } | 98 } |
95 | 99 |
96 std::unique_ptr<std::vector<unsigned>> lineEndings(const String16& text) | 100 std::unique_ptr<std::vector<unsigned>> lineEndings(const String16& text) |
97 { | 101 { |
98 std::unique_ptr<std::vector<unsigned>> result(new std::vector<unsigned>()); | 102 std::unique_ptr<std::vector<unsigned>> result(new std::vector<unsigned>()); |
99 | 103 |
104 String16 lineEndString = "\n"; | |
kozy
2016/08/09 16:40:37
const String16
| |
100 unsigned start = 0; | 105 unsigned start = 0; |
101 while (start < text.length()) { | 106 while (start < text.length()) { |
102 size_t lineEnd = text.find('\n', start); | 107 size_t lineEnd = text.find(lineEndString, start); |
103 if (lineEnd == kNotFound) | 108 if (lineEnd == kNotFound) |
104 break; | 109 break; |
105 | 110 |
106 result->push_back(static_cast<unsigned>(lineEnd)); | 111 result->push_back(static_cast<unsigned>(lineEnd)); |
107 start = lineEnd + 1; | 112 start = lineEnd + 1; |
108 } | 113 } |
109 result->push_back(text.length()); | 114 result->push_back(text.length()); |
110 | 115 |
111 return result; | 116 return result; |
112 } | 117 } |
113 | 118 |
114 std::vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Regex& regex, const String16& text) | 119 std::vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Regex& regex, const String16& text) |
115 { | 120 { |
116 std::vector<std::pair<int, String16>> result; | 121 std::vector<std::pair<int, String16>> result; |
117 if (text.isEmpty()) | 122 if (text.isEmpty()) |
118 return result; | 123 return result; |
119 | 124 |
120 std::unique_ptr<std::vector<unsigned>> endings(lineEndings(text)); | 125 std::unique_ptr<std::vector<unsigned>> endings(lineEndings(text)); |
121 unsigned size = endings->size(); | 126 unsigned size = endings->size(); |
122 unsigned start = 0; | 127 unsigned start = 0; |
123 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { | 128 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { |
124 unsigned lineEnd = endings->at(lineNumber); | 129 unsigned lineEnd = endings->at(lineNumber); |
125 String16 line = text.substring(start, lineEnd - start); | 130 String16 line = text.substring(start, lineEnd - start); |
126 if (line.endsWith('\r')) | 131 if (line.length() && line[line.length() - 1] == '\r') |
127 line = line.substring(0, line.length() - 1); | 132 line = line.substring(0, line.length() - 1); |
128 | 133 |
129 int matchLength; | 134 int matchLength; |
130 if (regex.match(line, 0, &matchLength) != -1) | 135 if (regex.match(line, 0, &matchLength) != -1) |
131 result.push_back(std::pair<int, String16>(lineNumber, line)); | 136 result.push_back(std::pair<int, String16>(lineNumber, line)); |
132 | 137 |
133 start = lineEnd + 1; | 138 start = lineEnd + 1; |
134 } | 139 } |
135 return result; | 140 return result; |
136 } | 141 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 return nullptr; | 279 return nullptr; |
275 jsonObject->setValue(toProtocolString(propertyName), std::move(prope rtyValue)); | 280 jsonObject->setValue(toProtocolString(propertyName), std::move(prope rtyValue)); |
276 } | 281 } |
277 return std::move(jsonObject); | 282 return std::move(jsonObject); |
278 } | 283 } |
279 NOTREACHED(); | 284 NOTREACHED(); |
280 return nullptr; | 285 return nullptr; |
281 } | 286 } |
282 | 287 |
283 } // namespace blink | 288 } // namespace blink |
OLD | NEW |