Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/inspector/search-util.cc

Issue 2332163002: [inspector] fixed all shorten-64-to-32 warnings (Closed)
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/injected-script.cc ('k') | src/inspector/string-16.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/search-util.h" 5 #include "src/inspector/search-util.h"
6 6
7 #include "src/inspector/protocol/Protocol.h" 7 #include "src/inspector/protocol/Protocol.h"
8 #include "src/inspector/v8-inspector-impl.h" 8 #include "src/inspector/v8-inspector-impl.h"
9 #include "src/inspector/v8-inspector-session-impl.h" 9 #include "src/inspector/v8-inspector-session-impl.h"
10 #include "src/inspector/v8-regex.h" 10 #include "src/inspector/v8-regex.h"
11 11
12 namespace v8_inspector { 12 namespace v8_inspector {
13 13
14 namespace { 14 namespace {
15 15
16 String16 findMagicComment(const String16& content, const String16& name, 16 String16 findMagicComment(const String16& content, const String16& name,
17 bool multiline) { 17 bool multiline) {
18 DCHECK(name.find("=") == String16::kNotFound); 18 DCHECK(name.find("=") == String16::kNotFound);
19 unsigned length = content.length(); 19 size_t length = content.length();
20 unsigned nameLength = name.length(); 20 size_t nameLength = name.length();
21 21
22 size_t pos = length; 22 size_t pos = length;
23 size_t equalSignPos = 0; 23 size_t equalSignPos = 0;
24 size_t closingCommentPos = 0; 24 size_t closingCommentPos = 0;
25 while (true) { 25 while (true) {
26 pos = content.reverseFind(name, pos); 26 pos = content.reverseFind(name, pos);
27 if (pos == String16::kNotFound) return String16(); 27 if (pos == String16::kNotFound) return String16();
28 28
29 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name. 29 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name.
30 if (pos < 4) return String16(); 30 if (pos < 4) return String16();
(...skipping 18 matching lines...) Expand all
49 DCHECK(!multiline || closingCommentPos); 49 DCHECK(!multiline || closingCommentPos);
50 size_t urlPos = equalSignPos + 1; 50 size_t urlPos = equalSignPos + 1;
51 String16 match = multiline 51 String16 match = multiline
52 ? content.substring(urlPos, closingCommentPos - urlPos) 52 ? content.substring(urlPos, closingCommentPos - urlPos)
53 : content.substring(urlPos); 53 : content.substring(urlPos);
54 54
55 size_t newLine = match.find("\n"); 55 size_t newLine = match.find("\n");
56 if (newLine != String16::kNotFound) match = match.substring(0, newLine); 56 if (newLine != String16::kNotFound) match = match.substring(0, newLine);
57 match = match.stripWhiteSpace(); 57 match = match.stripWhiteSpace();
58 58
59 for (unsigned i = 0; i < match.length(); ++i) { 59 for (size_t i = 0; i < match.length(); ++i) {
60 UChar c = match[i]; 60 UChar c = match[i];
61 if (c == '"' || c == '\'' || c == ' ' || c == '\t') return ""; 61 if (c == '"' || c == '\'' || c == ' ' || c == '\t') return "";
62 } 62 }
63 63
64 return match; 64 return match;
65 } 65 }
66 66
67 String16 createSearchRegexSource(const String16& text) { 67 String16 createSearchRegexSource(const String16& text) {
68 String16Builder result; 68 String16Builder result;
69 69
70 for (unsigned i = 0; i < text.length(); i++) { 70 for (size_t i = 0; i < text.length(); i++) {
71 UChar c = text[i]; 71 UChar c = text[i];
72 if (c == '[' || c == ']' || c == '(' || c == ')' || c == '{' || c == '}' || 72 if (c == '[' || c == ']' || c == '(' || c == ')' || c == '{' || c == '}' ||
73 c == '+' || c == '-' || c == '*' || c == '.' || c == ',' || c == '?' || 73 c == '+' || c == '-' || c == '*' || c == '.' || c == ',' || c == '?' ||
74 c == '\\' || c == '^' || c == '$' || c == '|') { 74 c == '\\' || c == '^' || c == '$' || c == '|') {
75 result.append('\\'); 75 result.append('\\');
76 } 76 }
77 result.append(c); 77 result.append(c);
78 } 78 }
79 79
80 return result.toString(); 80 return result.toString();
81 } 81 }
82 82
83 std::unique_ptr<std::vector<unsigned>> lineEndings(const String16& text) { 83 std::unique_ptr<std::vector<size_t>> lineEndings(const String16& text) {
84 std::unique_ptr<std::vector<unsigned>> result(new std::vector<unsigned>()); 84 std::unique_ptr<std::vector<size_t>> result(new std::vector<size_t>());
85 85
86 const String16 lineEndString = "\n"; 86 const String16 lineEndString = "\n";
87 unsigned start = 0; 87 size_t start = 0;
88 while (start < text.length()) { 88 while (start < text.length()) {
89 size_t lineEnd = text.find(lineEndString, start); 89 size_t lineEnd = text.find(lineEndString, start);
90 if (lineEnd == String16::kNotFound) break; 90 if (lineEnd == String16::kNotFound) break;
91 91
92 result->push_back(static_cast<unsigned>(lineEnd)); 92 result->push_back(lineEnd);
93 start = lineEnd + 1; 93 start = lineEnd + 1;
94 } 94 }
95 result->push_back(static_cast<unsigned>(text.length())); 95 result->push_back(text.length());
96 96
97 return result; 97 return result;
98 } 98 }
99 99
100 std::vector<std::pair<int, String16>> scriptRegexpMatchesByLines( 100 std::vector<std::pair<int, String16>> scriptRegexpMatchesByLines(
101 const V8Regex& regex, const String16& text) { 101 const V8Regex& regex, const String16& text) {
102 std::vector<std::pair<int, String16>> result; 102 std::vector<std::pair<int, String16>> result;
103 if (text.isEmpty()) return result; 103 if (text.isEmpty()) return result;
104 104
105 std::unique_ptr<std::vector<unsigned>> endings(lineEndings(text)); 105 std::unique_ptr<std::vector<size_t>> endings(lineEndings(text));
106 unsigned size = endings->size(); 106 size_t size = endings->size();
107 unsigned start = 0; 107 size_t start = 0;
108 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { 108 for (size_t lineNumber = 0; lineNumber < size; ++lineNumber) {
109 unsigned lineEnd = endings->at(lineNumber); 109 size_t lineEnd = endings->at(lineNumber);
110 String16 line = text.substring(start, lineEnd - start); 110 String16 line = text.substring(start, lineEnd - start);
111 if (line.length() && line[line.length() - 1] == '\r') 111 if (line.length() && line[line.length() - 1] == '\r')
112 line = line.substring(0, line.length() - 1); 112 line = line.substring(0, line.length() - 1);
113 113
114 int matchLength; 114 int matchLength;
115 if (regex.match(line, 0, &matchLength) != -1) 115 if (regex.match(line, 0, &matchLength) != -1)
116 result.push_back(std::pair<int, String16>(lineNumber, line)); 116 result.push_back(std::pair<int, String16>(lineNumber, line));
117 117
118 start = lineEnd + 1; 118 start = lineEnd + 1;
119 } 119 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 String16 findSourceURL(const String16& content, bool multiline) { 156 String16 findSourceURL(const String16& content, bool multiline) {
157 return findMagicComment(content, "sourceURL", multiline); 157 return findMagicComment(content, "sourceURL", multiline);
158 } 158 }
159 159
160 String16 findSourceMapURL(const String16& content, bool multiline) { 160 String16 findSourceMapURL(const String16& content, bool multiline) {
161 return findMagicComment(content, "sourceMappingURL", multiline); 161 return findMagicComment(content, "sourceMappingURL", multiline);
162 } 162 }
163 163
164 } // namespace v8_inspector 164 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/injected-script.cc ('k') | src/inspector/string-16.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698