| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @implements {WebInspector.ProjectSearchConfig} | 5 * @implements {Workspace.ProjectSearchConfig} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 WebInspector.SearchConfig = class { | 8 Workspace.SearchConfig = class { |
| 9 /** | 9 /** |
| 10 * @param {string} query | 10 * @param {string} query |
| 11 * @param {boolean} ignoreCase | 11 * @param {boolean} ignoreCase |
| 12 * @param {boolean} isRegex | 12 * @param {boolean} isRegex |
| 13 */ | 13 */ |
| 14 constructor(query, ignoreCase, isRegex) { | 14 constructor(query, ignoreCase, isRegex) { |
| 15 this._query = query; | 15 this._query = query; |
| 16 this._ignoreCase = ignoreCase; | 16 this._ignoreCase = ignoreCase; |
| 17 this._isRegex = isRegex; | 17 this._isRegex = isRegex; |
| 18 this._parse(); | 18 this._parse(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * @param {{query: string, ignoreCase: boolean, isRegex: boolean}} object | 22 * @param {{query: string, ignoreCase: boolean, isRegex: boolean}} object |
| 23 * @return {!WebInspector.SearchConfig} | 23 * @return {!Workspace.SearchConfig} |
| 24 */ | 24 */ |
| 25 static fromPlainObject(object) { | 25 static fromPlainObject(object) { |
| 26 return new WebInspector.SearchConfig(object.query, object.ignoreCase, object
.isRegex); | 26 return new Workspace.SearchConfig(object.query, object.ignoreCase, object.is
Regex); |
| 27 } | 27 } |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @override | 30 * @override |
| 31 * @return {string} | 31 * @return {string} |
| 32 */ | 32 */ |
| 33 query() { | 33 query() { |
| 34 return this._query; | 34 return this._query; |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 66 // A word is a sequence of any symbols except space and backslash or any sym
bols escaped with a backslash, that does not start with file:. | 66 // A word is a sequence of any symbols except space and backslash or any sym
bols escaped with a backslash, that does not start with file:. |
| 67 var unquotedWordPattern = '(\\s*(?!-?f(ile)?:)[^\\\\ ]|\\\\.)+'; | 67 var unquotedWordPattern = '(\\s*(?!-?f(ile)?:)[^\\\\ ]|\\\\.)+'; |
| 68 var unquotedPattern = | 68 var unquotedPattern = |
| 69 unquotedWordPattern + '( +' + unquotedWordPattern + ')*'; // A word or
several words separated by space(s). | 69 unquotedWordPattern + '( +' + unquotedWordPattern + ')*'; // A word or
several words separated by space(s). |
| 70 | 70 |
| 71 var pattern = '(' + filePattern + ')|(' + quotedPattern + ')|(' + unquotedPa
ttern + ')'; | 71 var pattern = '(' + filePattern + ')|(' + quotedPattern + ')|(' + unquotedPa
ttern + ')'; |
| 72 var regexp = new RegExp(pattern, 'g'); | 72 var regexp = new RegExp(pattern, 'g'); |
| 73 var queryParts = this._query.match(regexp) || []; | 73 var queryParts = this._query.match(regexp) || []; |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * @type {!Array.<!WebInspector.SearchConfig.QueryTerm>} | 76 * @type {!Array.<!Workspace.SearchConfig.QueryTerm>} |
| 77 */ | 77 */ |
| 78 this._fileQueries = []; | 78 this._fileQueries = []; |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * @type {!Array.<string>} | 81 * @type {!Array.<string>} |
| 82 */ | 82 */ |
| 83 this._queries = []; | 83 this._queries = []; |
| 84 | 84 |
| 85 for (var i = 0; i < queryParts.length; ++i) { | 85 for (var i = 0; i < queryParts.length; ++i) { |
| 86 var queryPart = queryParts[i]; | 86 var queryPart = queryParts[i]; |
| 87 if (!queryPart) | 87 if (!queryPart) |
| 88 continue; | 88 continue; |
| 89 var fileQuery = this._parseFileQuery(queryPart); | 89 var fileQuery = this._parseFileQuery(queryPart); |
| 90 if (fileQuery) { | 90 if (fileQuery) { |
| 91 this._fileQueries.push(fileQuery); | 91 this._fileQueries.push(fileQuery); |
| 92 /** @type {!Array.<!WebInspector.SearchConfig.RegexQuery>} */ | 92 /** @type {!Array.<!Workspace.SearchConfig.RegexQuery>} */ |
| 93 this._fileRegexQueries = this._fileRegexQueries || []; | 93 this._fileRegexQueries = this._fileRegexQueries || []; |
| 94 this._fileRegexQueries.push( | 94 this._fileRegexQueries.push( |
| 95 {regex: new RegExp(fileQuery.text, this.ignoreCase ? 'i' : ''), isNe
gative: fileQuery.isNegative}); | 95 {regex: new RegExp(fileQuery.text, this.ignoreCase ? 'i' : ''), isNe
gative: fileQuery.isNegative}); |
| 96 continue; | 96 continue; |
| 97 } | 97 } |
| 98 if (this._isRegex) { | 98 if (this._isRegex) { |
| 99 this._queries.push(queryPart); | 99 this._queries.push(queryPart); |
| 100 continue; | 100 continue; |
| 101 } | 101 } |
| 102 if (queryPart.startsWith('"')) { | 102 if (queryPart.startsWith('"')) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 _parseUnquotedQuery(query) { | 135 _parseUnquotedQuery(query) { |
| 136 return query.replace(/\\(.)/g, '$1'); | 136 return query.replace(/\\(.)/g, '$1'); |
| 137 } | 137 } |
| 138 | 138 |
| 139 _parseQuotedQuery(query) { | 139 _parseQuotedQuery(query) { |
| 140 return query.substring(1, query.length - 1).replace(/\\(.)/g, '$1'); | 140 return query.substring(1, query.length - 1).replace(/\\(.)/g, '$1'); |
| 141 } | 141 } |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * @param {string} query | 144 * @param {string} query |
| 145 * @return {?WebInspector.SearchConfig.QueryTerm} | 145 * @return {?Workspace.SearchConfig.QueryTerm} |
| 146 */ | 146 */ |
| 147 _parseFileQuery(query) { | 147 _parseFileQuery(query) { |
| 148 var match = query.match(/^(-)?f(ile)?:/); | 148 var match = query.match(/^(-)?f(ile)?:/); |
| 149 if (!match) | 149 if (!match) |
| 150 return null; | 150 return null; |
| 151 var isNegative = !!match[1]; | 151 var isNegative = !!match[1]; |
| 152 query = query.substr(match[0].length); | 152 query = query.substr(match[0].length); |
| 153 var result = ''; | 153 var result = ''; |
| 154 for (var i = 0; i < query.length; ++i) { | 154 for (var i = 0; i < query.length; ++i) { |
| 155 var char = query[i]; | 155 var char = query[i]; |
| 156 if (char === '*') { | 156 if (char === '*') { |
| 157 result += '.*'; | 157 result += '.*'; |
| 158 } else if (char === '\\') { | 158 } else if (char === '\\') { |
| 159 ++i; | 159 ++i; |
| 160 var nextChar = query[i]; | 160 var nextChar = query[i]; |
| 161 if (nextChar === ' ') | 161 if (nextChar === ' ') |
| 162 result += ' '; | 162 result += ' '; |
| 163 } else { | 163 } else { |
| 164 if (String.regexSpecialCharacters().indexOf(query.charAt(i)) !== -1) | 164 if (String.regexSpecialCharacters().indexOf(query.charAt(i)) !== -1) |
| 165 result += '\\'; | 165 result += '\\'; |
| 166 result += query.charAt(i); | 166 result += query.charAt(i); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 return new WebInspector.SearchConfig.QueryTerm(result, isNegative); | 169 return new Workspace.SearchConfig.QueryTerm(result, isNegative); |
| 170 } | 170 } |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */ | 173 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */ |
| 174 WebInspector.SearchConfig.RegexQuery; | 174 Workspace.SearchConfig.RegexQuery; |
| 175 | 175 |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @unrestricted | 178 * @unrestricted |
| 179 */ | 179 */ |
| 180 WebInspector.SearchConfig.QueryTerm = class { | 180 Workspace.SearchConfig.QueryTerm = class { |
| 181 /** | 181 /** |
| 182 * @param {string} text | 182 * @param {string} text |
| 183 * @param {boolean} isNegative | 183 * @param {boolean} isNegative |
| 184 */ | 184 */ |
| 185 constructor(text, isNegative) { | 185 constructor(text, isNegative) { |
| 186 this.text = text; | 186 this.text = text; |
| 187 this.isNegative = isNegative; | 187 this.isNegative = isNegative; |
| 188 } | 188 } |
| 189 }; | 189 }; |
| OLD | NEW |