| OLD | NEW |
| 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 * TablePrinter is a helper to format a table as ASCII art or an HTML table. | 6 * TablePrinter is a helper to format a table as ASCII art or an HTML table. |
| 7 * | 7 * |
| 8 * Usage: call addRow() and addCell() repeatedly to specify the data. | 8 * Usage: call addRow() and addCell() repeatedly to specify the data. |
| 9 * | 9 * |
| 10 * addHeaderCell() can optionally be called to specify header cells for a | 10 * addHeaderCell() can optionally be called to specify header cells for a |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 getCell_: function(rowIndex, columnIndex) { | 104 getCell_: function(rowIndex, columnIndex) { |
| 105 if (rowIndex >= this.rows_.length) | 105 if (rowIndex >= this.rows_.length) |
| 106 return null; | 106 return null; |
| 107 var row = this.rows_[rowIndex]; | 107 var row = this.rows_[rowIndex]; |
| 108 if (columnIndex >= row.length) | 108 if (columnIndex >= row.length) |
| 109 return null; | 109 return null; |
| 110 return row[columnIndex]; | 110 return row[columnIndex]; |
| 111 }, | 111 }, |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * Returns true if searchString can be found entirely within a cell. |
| 115 * Case insensitive. |
| 116 * |
| 117 * @param {string} string String to search for, must be lowercase. |
| 118 * @return {boolean} True if some cell contains searchString. |
| 119 */ |
| 120 search: function(searchString) { |
| 121 var numColumns = this.getNumColumns(); |
| 122 for (var r = 0; r < this.rows_.length; ++r) { |
| 123 for (var c = 0; c < numColumns; ++c) { |
| 124 var cell = this.getCell_(r, c); |
| 125 if (!cell) |
| 126 continue; |
| 127 if (cell.text.toLowerCase().indexOf(searchString) != -1) |
| 128 return true; |
| 129 } |
| 130 } |
| 131 return false; |
| 132 }, |
| 133 |
| 134 /** |
| 114 * Prints a formatted text representation of the table data to the | 135 * Prints a formatted text representation of the table data to the |
| 115 * node |parent|. |spacing| indicates number of extra spaces, if any, | 136 * node |parent|. |spacing| indicates number of extra spaces, if any, |
| 116 * to add between columns. | 137 * to add between columns. |
| 117 */ | 138 */ |
| 118 toText: function(spacing, parent) { | 139 toText: function(spacing, parent) { |
| 119 var pre = addNode(parent, 'pre'); | 140 var pre = addNode(parent, 'pre'); |
| 120 var numColumns = this.getNumColumns(); | 141 var numColumns = this.getNumColumns(); |
| 121 | 142 |
| 122 // Figure out the maximum width of each column. | 143 // Figure out the maximum width of each column. |
| 123 var columnWidths = []; | 144 var columnWidths = []; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 */ | 280 */ |
| 260 function TablePrinterCell(value) { | 281 function TablePrinterCell(value) { |
| 261 this.text = '' + value; | 282 this.text = '' + value; |
| 262 this.link = null; | 283 this.link = null; |
| 263 this.alignRight = false; | 284 this.alignRight = false; |
| 264 this.allowOverflow = false; | 285 this.allowOverflow = false; |
| 265 } | 286 } |
| 266 | 287 |
| 267 return TablePrinter; | 288 return TablePrinter; |
| 268 })(); | 289 })(); |
| OLD | NEW |