Chromium Code Reviews| 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 {Workspace.ProjectSearchConfig} | 5 * @implements {Workspace.ProjectSearchConfig} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Workspace.SearchConfig = class { | 8 Workspace.SearchConfig = class { |
| 9 /** | 9 /** |
| 10 * @param {string} query | 10 * @param {string} query |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * @return {{query: string, ignoreCase: boolean, isRegex: boolean}} | 54 * @return {{query: string, ignoreCase: boolean, isRegex: boolean}} |
| 55 */ | 55 */ |
| 56 toPlainObject() { | 56 toPlainObject() { |
| 57 return {query: this.query(), ignoreCase: this.ignoreCase(), isRegex: this.is Regex()}; | 57 return {query: this.query(), ignoreCase: this.ignoreCase(), isRegex: this.is Regex()}; |
| 58 } | 58 } |
| 59 | 59 |
| 60 _parse() { | 60 _parse() { |
| 61 var filePattern = | 61 // Inside double quotes: any symbol except double quote and backslash or any symbol escaped with a backslash. |
| 62 '-?f(ile)?:(([^\\\\ ]|\\\\.)+)'; // After file: prefix: any symbol exce pt space and backslash or any symbol escaped with a backslash. | 62 var quotedPattern = /"([^\\"]|\\.)+"/; |
|
lushnikov
2017/01/30 10:03:42
these are just strings re-written as regex literal
| |
| 63 var quotedPattern = | 63 // 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:. |
| 64 '"(([^\\\\"]|\\\\.)+)"'; // Inside double quotes: any symbol except dou ble quote and backslash or any symbol escaped with a backslash. | 64 var unquotedWordPattern = /(\s*(?!-?f(ile)?:)[^\\ ]|\\.)+/; |
| 65 var unquotedPattern = unquotedWordPattern.source + '( +' + unquotedWordPatte rn.source + ')*'; | |
|
dgozman
2017/01/30 16:54:42
I'm curious why we use ' ' instead of '\s' ?
lushnikov
2017/01/31 02:47:21
Looks like there's no good reason. Updated the CL
| |
| 65 | 66 |
| 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)?:)[^\\\\ ]|\\\\.)+'; | |
| 68 var unquotedPattern = | |
| 69 unquotedWordPattern + '( +' + unquotedWordPattern + ')*'; // A word or several words separated by space(s). | |
| 70 | 67 |
| 71 var pattern = '(' + filePattern + ')|(' + quotedPattern + ')|(' + unquotedPa ttern + ')'; | 68 var pattern = [ |
| 69 '(\\s*' + Workspace.SearchConfig.FilePatternRegex.source + '\\s*)', | |
|
lushnikov
2017/01/30 10:03:42
the "\\s*" is the bugfix - swallowing of the white
| |
| 70 '(' + quotedPattern.source + ')', | |
| 71 '(' + unquotedPattern + ')', | |
| 72 ].join('|'); | |
| 72 var regexp = new RegExp(pattern, 'g'); | 73 var regexp = new RegExp(pattern, 'g'); |
| 73 var queryParts = this._query.match(regexp) || []; | 74 var queryParts = this._query.match(regexp) || []; |
| 74 | |
| 75 /** | 75 /** |
| 76 * @type {!Array.<!Workspace.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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 {?Workspace.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(Workspace.SearchConfig.FilePatternRegex); |
| 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 = match[3]; |
|
lushnikov
2017/01/30 10:03:41
but here we still want to use only the actual file
| |
| 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 Workspace.SearchConfig.QueryTerm(result, isNegative); | 169 return new Workspace.SearchConfig.QueryTerm(result, isNegative); |
| 170 } | 170 } |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 // After file: prefix: any symbol except space and backslash or any symbol escap ed with a backslash. | |
| 174 Workspace.SearchConfig.FilePatternRegex = /(-)?f(ile)?:((?:[^\\ ]|\\.)+)/; | |
|
lushnikov
2017/01/30 10:03:42
this is the "filePattern" regex, written as regex
| |
| 175 | |
| 173 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */ | 176 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */ |
| 174 Workspace.SearchConfig.RegexQuery; | 177 Workspace.SearchConfig.RegexQuery; |
| 175 | 178 |
| 176 | 179 |
| 177 /** | 180 /** |
| 178 * @unrestricted | 181 * @unrestricted |
| 179 */ | 182 */ |
| 180 Workspace.SearchConfig.QueryTerm = class { | 183 Workspace.SearchConfig.QueryTerm = class { |
| 181 /** | 184 /** |
| 182 * @param {string} text | 185 * @param {string} text |
| 183 * @param {boolean} isNegative | 186 * @param {boolean} isNegative |
| 184 */ | 187 */ |
| 185 constructor(text, isNegative) { | 188 constructor(text, isNegative) { |
| 186 this.text = text; | 189 this.text = text; |
| 187 this.isNegative = isNegative; | 190 this.isNegative = isNegative; |
| 188 } | 191 } |
| 189 }; | 192 }; |
| OLD | NEW |