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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/TextUtils.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 WebInspector.TextUtils = { 30 Common.TextUtils = {
31 /** 31 /**
32 * @param {string} char 32 * @param {string} char
33 * @return {boolean} 33 * @return {boolean}
34 */ 34 */
35 isStopChar: function(char) { 35 isStopChar: function(char) {
36 return (char > ' ' && char < '0') || (char > '9' && char < 'A') || (char > ' Z' && char < '_') || 36 return (char > ' ' && char < '0') || (char > '9' && char < 'A') || (char > ' Z' && char < '_') ||
37 (char > '_' && char < 'a') || (char > 'z' && char <= '~'); 37 (char > '_' && char < 'a') || (char > 'z' && char <= '~');
38 }, 38 },
39 39
40 /** 40 /**
41 * @param {string} char 41 * @param {string} char
42 * @return {boolean} 42 * @return {boolean}
43 */ 43 */
44 isWordChar: function(char) { 44 isWordChar: function(char) {
45 return !WebInspector.TextUtils.isStopChar(char) && !WebInspector.TextUtils.i sSpaceChar(char); 45 return !Common.TextUtils.isStopChar(char) && !Common.TextUtils.isSpaceChar(c har);
46 }, 46 },
47 47
48 /** 48 /**
49 * @param {string} char 49 * @param {string} char
50 * @return {boolean} 50 * @return {boolean}
51 */ 51 */
52 isSpaceChar: function(char) { 52 isSpaceChar: function(char) {
53 return WebInspector.TextUtils._SpaceCharRegex.test(char); 53 return Common.TextUtils._SpaceCharRegex.test(char);
54 }, 54 },
55 55
56 /** 56 /**
57 * @param {string} word 57 * @param {string} word
58 * @return {boolean} 58 * @return {boolean}
59 */ 59 */
60 isWord: function(word) { 60 isWord: function(word) {
61 for (var i = 0; i < word.length; ++i) { 61 for (var i = 0; i < word.length; ++i) {
62 if (!WebInspector.TextUtils.isWordChar(word.charAt(i))) 62 if (!Common.TextUtils.isWordChar(word.charAt(i)))
63 return false; 63 return false;
64 } 64 }
65 return true; 65 return true;
66 }, 66 },
67 67
68 /** 68 /**
69 * @param {string} char 69 * @param {string} char
70 * @return {boolean} 70 * @return {boolean}
71 */ 71 */
72 isOpeningBraceChar: function(char) { 72 isOpeningBraceChar: function(char) {
73 return char === '(' || char === '{'; 73 return char === '(' || char === '{';
74 }, 74 },
75 75
76 /** 76 /**
77 * @param {string} char 77 * @param {string} char
78 * @return {boolean} 78 * @return {boolean}
79 */ 79 */
80 isClosingBraceChar: function(char) { 80 isClosingBraceChar: function(char) {
81 return char === ')' || char === '}'; 81 return char === ')' || char === '}';
82 }, 82 },
83 83
84 /** 84 /**
85 * @param {string} char 85 * @param {string} char
86 * @return {boolean} 86 * @return {boolean}
87 */ 87 */
88 isBraceChar: function(char) { 88 isBraceChar: function(char) {
89 return WebInspector.TextUtils.isOpeningBraceChar(char) || WebInspector.TextU tils.isClosingBraceChar(char); 89 return Common.TextUtils.isOpeningBraceChar(char) || Common.TextUtils.isClosi ngBraceChar(char);
90 }, 90 },
91 91
92 /** 92 /**
93 * @param {string} text 93 * @param {string} text
94 * @param {function(string):boolean} isWordChar 94 * @param {function(string):boolean} isWordChar
95 * @param {function(string)} wordCallback 95 * @param {function(string)} wordCallback
96 */ 96 */
97 textToWords: function(text, isWordChar, wordCallback) { 97 textToWords: function(text, isWordChar, wordCallback) {
98 var startWord = -1; 98 var startWord = -1;
99 for (var i = 0; i < text.length; ++i) { 99 for (var i = 0; i < text.length; ++i) {
100 if (!isWordChar(text.charAt(i))) { 100 if (!isWordChar(text.charAt(i))) {
101 if (startWord !== -1) 101 if (startWord !== -1)
102 wordCallback(text.substring(startWord, i)); 102 wordCallback(text.substring(startWord, i));
103 startWord = -1; 103 startWord = -1;
104 } else if (startWord === -1) 104 } else if (startWord === -1)
105 startWord = i; 105 startWord = i;
106 } 106 }
107 if (startWord !== -1) 107 if (startWord !== -1)
108 wordCallback(text.substring(startWord)); 108 wordCallback(text.substring(startWord));
109 }, 109 },
110 110
111 /** 111 /**
112 * @param {string} line 112 * @param {string} line
113 * @return {string} 113 * @return {string}
114 */ 114 */
115 lineIndent: function(line) { 115 lineIndent: function(line) {
116 var indentation = 0; 116 var indentation = 0;
117 while (indentation < line.length && WebInspector.TextUtils.isSpaceChar(line. charAt(indentation))) 117 while (indentation < line.length && Common.TextUtils.isSpaceChar(line.charAt (indentation)))
118 ++indentation; 118 ++indentation;
119 return line.substr(0, indentation); 119 return line.substr(0, indentation);
120 }, 120 },
121 121
122 /** 122 /**
123 * @param {string} text 123 * @param {string} text
124 * @return {boolean} 124 * @return {boolean}
125 */ 125 */
126 isUpperCase: function(text) { 126 isUpperCase: function(text) {
127 return text === text.toUpperCase(); 127 return text === text.toUpperCase();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 matches.push({value: match, position: startIndex + result.index, regexIn dex: regexIndex}); 176 matches.push({value: match, position: startIndex + result.index, regexIn dex: regexIndex});
177 currentIndex = result.index + match.length; 177 currentIndex = result.index + match.length;
178 } 178 }
179 var stringAfterMatches = text.substring(currentIndex); 179 var stringAfterMatches = text.substring(currentIndex);
180 if (stringAfterMatches) 180 if (stringAfterMatches)
181 doSplit(stringAfterMatches, regexIndex + 1, startIndex + currentIndex); 181 doSplit(stringAfterMatches, regexIndex + 1, startIndex + currentIndex);
182 } 182 }
183 } 183 }
184 }; 184 };
185 185
186 WebInspector.TextUtils._SpaceCharRegex = /\s/; 186 Common.TextUtils._SpaceCharRegex = /\s/;
187 187
188 /** 188 /**
189 * @enum {string} 189 * @enum {string}
190 */ 190 */
191 WebInspector.TextUtils.Indent = { 191 Common.TextUtils.Indent = {
192 TwoSpaces: ' ', 192 TwoSpaces: ' ',
193 FourSpaces: ' ', 193 FourSpaces: ' ',
194 EightSpaces: ' ', 194 EightSpaces: ' ',
195 TabCharacter: '\t' 195 TabCharacter: '\t'
196 }; 196 };
197 197
198 /** 198 /**
199 * @unrestricted 199 * @unrestricted
200 */ 200 */
201 WebInspector.TextUtils.BalancedJSONTokenizer = class { 201 Common.TextUtils.BalancedJSONTokenizer = class {
202 /** 202 /**
203 * @param {function(string)} callback 203 * @param {function(string)} callback
204 * @param {boolean=} findMultiple 204 * @param {boolean=} findMultiple
205 */ 205 */
206 constructor(callback, findMultiple) { 206 constructor(callback, findMultiple) {
207 this._callback = callback; 207 this._callback = callback;
208 this._index = 0; 208 this._index = 0;
209 this._balance = 0; 209 this._balance = 0;
210 this._buffer = ''; 210 this._buffer = '';
211 this._findMultiple = findMultiple || false; 211 this._findMultiple = findMultiple || false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 * @return {string} 263 * @return {string}
264 */ 264 */
265 remainder() { 265 remainder() {
266 return this._buffer; 266 return this._buffer;
267 } 267 }
268 }; 268 };
269 269
270 /** 270 /**
271 * @interface 271 * @interface
272 */ 272 */
273 WebInspector.TokenizerFactory = function() {}; 273 Common.TokenizerFactory = function() {};
274 274
275 WebInspector.TokenizerFactory.prototype = { 275 Common.TokenizerFactory.prototype = {
276 /** 276 /**
277 * @param {string} mimeType 277 * @param {string} mimeType
278 * @return {function(string, function(string, ?string, number, number))} 278 * @return {function(string, function(string, ?string, number, number))}
279 */ 279 */
280 createTokenizer: function(mimeType) {} 280 createTokenizer: function(mimeType) {}
281 }; 281 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698