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" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 String16 findMagicComment(const String16& content, const String16& name, bool mu ltiline, bool* deprecated) | 16 String16 findMagicComment(const String16& content, const String16& name, bool mu ltiline, bool* deprecated) |
17 { | 17 { |
18 DCHECK(name.find("=") == kNotFound); | 18 DCHECK(name.find("=") == String16::kNotFound); |
19 if (deprecated) | 19 if (deprecated) |
20 *deprecated = false; | 20 *deprecated = false; |
21 | 21 |
22 unsigned length = content.length(); | 22 unsigned length = content.length(); |
23 unsigned nameLength = name.length(); | 23 unsigned nameLength = name.length(); |
24 | 24 |
25 size_t pos = length; | 25 size_t pos = length; |
26 size_t equalSignPos = 0; | 26 size_t equalSignPos = 0; |
27 size_t closingCommentPos = 0; | 27 size_t closingCommentPos = 0; |
28 while (true) { | 28 while (true) { |
29 pos = content.reverseFind(name, pos); | 29 pos = content.reverseFind(name, pos); |
30 if (pos == kNotFound) | 30 if (pos == String16::kNotFound) |
31 return String16(); | 31 return String16(); |
32 | 32 |
33 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name . | 33 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name . |
34 if (pos < 4) | 34 if (pos < 4) |
35 return String16(); | 35 return String16(); |
36 pos -= 4; | 36 pos -= 4; |
37 if (content[pos] != '/') | 37 if (content[pos] != '/') |
38 continue; | 38 continue; |
39 if ((content[pos + 1] != '/' || multiline) | 39 if ((content[pos + 1] != '/' || multiline) |
40 && (content[pos + 1] != '*' || !multiline)) | 40 && (content[pos + 1] != '*' || !multiline)) |
41 continue; | 41 continue; |
42 if (content[pos + 2] != '#' && content[pos + 2] != '@') | 42 if (content[pos + 2] != '#' && content[pos + 2] != '@') |
43 continue; | 43 continue; |
44 if (content[pos + 3] != ' ' && content[pos + 3] != '\t') | 44 if (content[pos + 3] != ' ' && content[pos + 3] != '\t') |
45 continue; | 45 continue; |
46 equalSignPos = pos + 4 + nameLength; | 46 equalSignPos = pos + 4 + nameLength; |
47 if (equalSignPos < length && content[equalSignPos] != '=') | 47 if (equalSignPos < length && content[equalSignPos] != '=') |
48 continue; | 48 continue; |
49 if (multiline) { | 49 if (multiline) { |
50 closingCommentPos = content.find("*/", equalSignPos + 1); | 50 closingCommentPos = content.find("*/", equalSignPos + 1); |
51 if (closingCommentPos == kNotFound) | 51 if (closingCommentPos == String16::kNotFound) |
52 return String16(); | 52 return String16(); |
53 } | 53 } |
54 | 54 |
55 break; | 55 break; |
56 } | 56 } |
57 | 57 |
58 if (deprecated && content[pos + 2] == '@') | 58 if (deprecated && content[pos + 2] == '@') |
59 *deprecated = true; | 59 *deprecated = true; |
60 | 60 |
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 != String16::kNotFound) |
70 match = match.substring(0, newLine); | 70 match = match.substring(0, newLine); |
71 match = match.stripWhiteSpace(); | 71 match = match.stripWhiteSpace(); |
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("[](){}+-*.,?\\^$|"); |
caseq
2016/08/13 00:28:54
unused now?
dgozman
2016/08/13 04:49:59
Done.
| |
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 const String16 lineEndString = "\n"; | |
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 == String16::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 |