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

Side by Side Diff: chrome/browser/resources/print_preview/print_preview_utils.js

Issue 917093003: Shorten Closure template notation from Array.<*> to Array<*>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove cvox Created 5 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * @param {string} toTest The string to be tested. 6 * @param {string} toTest The string to be tested.
7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing 7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing
8 * whitespace is allowed. 8 * whitespace is allowed.
9 */ 9 */
10 function isInteger(toTest) { 10 function isInteger(toTest) {
11 var numericExp = /^\s*[0-9]+\s*$/; 11 var numericExp = /^\s*[0-9]+\s*$/;
12 return numericExp.test(toTest); 12 return numericExp.test(toTest);
13 } 13 }
14 14
15 /** 15 /**
16 * Returns true if |value| is a valid non zero positive integer. 16 * Returns true if |value| is a valid non zero positive integer.
17 * @param {string} value The string to be tested. 17 * @param {string} value The string to be tested.
18 * @return {boolean} true if the |value| is valid non zero positive integer. 18 * @return {boolean} true if the |value| is valid non zero positive integer.
19 */ 19 */
20 function isPositiveInteger(value) { 20 function isPositiveInteger(value) {
21 return isInteger(value) && parseInt(value, 10) > 0; 21 return isInteger(value) && parseInt(value, 10) > 0;
22 } 22 }
23 23
24 /** 24 /**
25 * Returns true if the contents of the two arrays are equal. 25 * Returns true if the contents of the two arrays are equal.
26 * @param {Array.<{from: number, to: number}>} array1 The first array. 26 * @param {Array<{from: number, to: number}>} array1 The first array.
27 * @param {Array.<{from: number, to: number}>} array2 The second array. 27 * @param {Array<{from: number, to: number}>} array2 The second array.
28 * @return {boolean} true if the arrays are equal. 28 * @return {boolean} true if the arrays are equal.
29 */ 29 */
30 function areArraysEqual(array1, array2) { 30 function areArraysEqual(array1, array2) {
31 if (array1.length != array2.length) 31 if (array1.length != array2.length)
32 return false; 32 return false;
33 for (var i = 0; i < array1.length; i++) 33 for (var i = 0; i < array1.length; i++)
34 if (array1[i] !== array2[i]) 34 if (array1[i] !== array2[i])
35 return false; 35 return false;
36 return true; 36 return true;
37 } 37 }
(...skipping 11 matching lines...) Expand all
49 if (array1[i].from != array2[i].from || 49 if (array1[i].from != array2[i].from ||
50 array1[i].to != array2[i].to) { 50 array1[i].to != array2[i].to) {
51 return false; 51 return false;
52 } 52 }
53 return true; 53 return true;
54 } 54 }
55 55
56 /** 56 /**
57 * Removes duplicate elements from |inArray| and returns a new array. 57 * Removes duplicate elements from |inArray| and returns a new array.
58 * |inArray| is not affected. It assumes that |inArray| is already sorted. 58 * |inArray| is not affected. It assumes that |inArray| is already sorted.
59 * @param {!Array.<number>} inArray The array to be processed. 59 * @param {!Array<number>} inArray The array to be processed.
60 * @return {!Array.<number>} The array after processing. 60 * @return {!Array<number>} The array after processing.
61 */ 61 */
62 function removeDuplicates(inArray) { 62 function removeDuplicates(inArray) {
63 var out = []; 63 var out = [];
64 64
65 if (inArray.length == 0) 65 if (inArray.length == 0)
66 return out; 66 return out;
67 67
68 out.push(inArray[0]); 68 out.push(inArray[0]);
69 for (var i = 1; i < inArray.length; ++i) 69 for (var i = 1; i < inArray.length; ++i)
70 if (inArray[i] != inArray[i - 1]) 70 if (inArray[i] != inArray[i - 1])
(...skipping 16 matching lines...) Expand all
87 * missed then |totalPageCount| is used as the second number. 87 * missed then |totalPageCount| is used as the second number.
88 * Example: "1-4, 9, 3-6, 10, 11" is valid, assuming |totalPageCount| >= 11. 88 * Example: "1-4, 9, 3-6, 10, 11" is valid, assuming |totalPageCount| >= 11.
89 * Example: "1-4, -6" is valid, assuming |totalPageCount| >= 6. 89 * Example: "1-4, -6" is valid, assuming |totalPageCount| >= 6.
90 * Example: "2-" is valid, assuming |totalPageCount| >= 2, means from 2 to the 90 * Example: "2-" is valid, assuming |totalPageCount| >= 2, means from 2 to the
91 * end. 91 * end.
92 * Example: "4-2, 11, -6" is invalid. 92 * Example: "4-2, 11, -6" is invalid.
93 * Example: "-" is valid, assuming |totalPageCount| >= 1. 93 * Example: "-" is valid, assuming |totalPageCount| >= 1.
94 * Example: "1-4dsf, 11" is invalid regardless of |totalPageCount|. 94 * Example: "1-4dsf, 11" is invalid regardless of |totalPageCount|.
95 * @param {string} pageRangeText The text to be checked. 95 * @param {string} pageRangeText The text to be checked.
96 * @param {number=} opt_totalPageCount The total number of pages. 96 * @param {number=} opt_totalPageCount The total number of pages.
97 * @return {Array.<{from: number, to: number}>} An array of page range objects. 97 * @return {Array<{from: number, to: number}>} An array of page range objects.
98 */ 98 */
99 function pageRangeTextToPageRanges(pageRangeText, opt_totalPageCount) { 99 function pageRangeTextToPageRanges(pageRangeText, opt_totalPageCount) {
100 if (pageRangeText == '') { 100 if (pageRangeText == '') {
101 return []; 101 return [];
102 } 102 }
103 103
104 var MAX_PAGE_NUMBER = 1000000000; 104 var MAX_PAGE_NUMBER = 1000000000;
105 var totalPageCount = opt_totalPageCount ? opt_totalPageCount : 105 var totalPageCount = opt_totalPageCount ? opt_totalPageCount :
106 MAX_PAGE_NUMBER; 106 MAX_PAGE_NUMBER;
107 107
(...skipping 26 matching lines...) Expand all
134 } 134 }
135 135
136 /** 136 /**
137 * Returns a list of pages defined by |pagesRangeText|. The pages are 137 * Returns a list of pages defined by |pagesRangeText|. The pages are
138 * listed in the order they appear in |pageRangeText| and duplicates are not 138 * listed in the order they appear in |pageRangeText| and duplicates are not
139 * eliminated. If |pageRangeText| is not valid according or 139 * eliminated. If |pageRangeText| is not valid according or
140 * |totalPageCount| undefined [1,2,...,totalPageCount] is returned. 140 * |totalPageCount| undefined [1,2,...,totalPageCount] is returned.
141 * See pageRangeTextToPageRanges for details. 141 * See pageRangeTextToPageRanges for details.
142 * @param {string} pageRangeText The text to be checked. 142 * @param {string} pageRangeText The text to be checked.
143 * @param {number} totalPageCount The total number of pages. 143 * @param {number} totalPageCount The total number of pages.
144 * @return {Array.<number>} A list of all pages. 144 * @return {Array<number>} A list of all pages.
145 */ 145 */
146 function pageRangeTextToPageList(pageRangeText, totalPageCount) { 146 function pageRangeTextToPageList(pageRangeText, totalPageCount) {
147 var pageRanges = pageRangeTextToPageRanges(pageRangeText, totalPageCount); 147 var pageRanges = pageRangeTextToPageRanges(pageRangeText, totalPageCount);
148 var pageList = []; 148 var pageList = [];
149 if (pageRanges) { 149 if (pageRanges) {
150 for (var i = 0; i < pageRanges.length; ++i) { 150 for (var i = 0; i < pageRanges.length; ++i) {
151 for (var j = pageRanges[i].from; j <= Math.min(pageRanges[i].to, 151 for (var j = pageRanges[i].from; j <= Math.min(pageRanges[i].to,
152 totalPageCount); ++j) { 152 totalPageCount); ++j) {
153 pageList.push(j); 153 pageList.push(j);
154 } 154 }
155 } 155 }
156 } 156 }
157 if (pageList.length == 0) { 157 if (pageList.length == 0) {
158 for (var j = 1; j <= totalPageCount; ++j) 158 for (var j = 1; j <= totalPageCount; ++j)
159 pageList.push(j); 159 pageList.push(j);
160 } 160 }
161 return pageList; 161 return pageList;
162 } 162 }
163 163
164 /** 164 /**
165 * @param {!Array.<number>} pageList The list to be processed. 165 * @param {!Array<number>} pageList The list to be processed.
166 * @return {!Array.<number>} The contents of |pageList| in ascending order and 166 * @return {!Array<number>} The contents of |pageList| in ascending order and
167 * without any duplicates. |pageList| is not affected. 167 * without any duplicates. |pageList| is not affected.
168 */ 168 */
169 function pageListToPageSet(pageList) { 169 function pageListToPageSet(pageList) {
170 var pageSet = []; 170 var pageSet = [];
171 if (pageList.length == 0) 171 if (pageList.length == 0)
172 return pageSet; 172 return pageSet;
173 pageSet = pageList.slice(0); 173 pageSet = pageList.slice(0);
174 pageSet.sort(function(a, b) { 174 pageSet.sort(function(a, b) {
175 return /** @type {number} */(a) - /** @type {number} */(b); 175 return /** @type {number} */(a) - /** @type {number} */(b);
176 }); 176 });
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * localizedStrings An array of strings with corresponding locales. 225 * localizedStrings An array of strings with corresponding locales.
226 * @return {string} A string for the current locale. An empty string if there's 226 * @return {string} A string for the current locale. An empty string if there's
227 * no string for the current locale found. 227 * no string for the current locale found.
228 */ 228 */
229 function getStringForCurrentLocale(localizedStrings) { 229 function getStringForCurrentLocale(localizedStrings) {
230 // First try to find an exact match and then look for the language only. 230 // First try to find an exact match and then look for the language only.
231 return getStringForLocale(localizedStrings, navigator.language) || 231 return getStringForLocale(localizedStrings, navigator.language) ||
232 getStringForLocale(localizedStrings, 232 getStringForLocale(localizedStrings,
233 navigator.language.split('-')[0]); 233 navigator.language.split('-')[0]);
234 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698