remove duplicate functions.

This commit is contained in:
Christopher Jeffrey 2015-03-31 02:49:29 -07:00
parent 064a4e9086
commit 7a3525be77
1 changed files with 11 additions and 18 deletions

View File

@ -2303,6 +2303,13 @@ Element.prototype.parseContent = function(noTags) {
return false; return false;
}; };
Element.prototype.textLength = function(text) {
if (!this.options.tags && !this.options.parseTags) {
return text.length;
}
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length;
};
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`. // Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
Element.prototype._parseTags = function(text) { Element.prototype._parseTags = function(text) {
if (!this.parseTags) return text; if (!this.parseTags) return text;
@ -7005,7 +7012,7 @@ Table.prototype.setData = function(rows) {
this.rows.forEach(function(row) { this.rows.forEach(function(row) {
row.forEach(function(cell, i) { row.forEach(function(cell, i) {
var clen = self._cellLength(cell); var clen = self.textLength(cell);
if (!maxes[i] || maxes[i] < clen + self.pad) { if (!maxes[i] || maxes[i] < clen + self.pad) {
maxes[i] = clen + self.pad; maxes[i] = clen + self.pad;
} }
@ -7023,7 +7030,7 @@ Table.prototype.setData = function(rows) {
var isFooter = i === self.rows.length - 1; var isFooter = i === self.rows.length - 1;
row.forEach(function(cell, i) { row.forEach(function(cell, i) {
var width = maxes[i]; var width = maxes[i];
var clen = self._cellLength(cell); var clen = self.textLength(cell);
if (i !== 0) { if (i !== 0) {
text += ' '; text += ' ';
@ -7082,13 +7089,6 @@ Table.prototype.setData = function(rows) {
this.align = align; this.align = align;
}; };
Table.prototype._cellLength = function(text) {
if (!this.options.tags && !this.options.parseTags) {
return text.length;
}
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length;
};
Table.prototype.render = function() { Table.prototype.render = function() {
var self = this; var self = this;
@ -7292,7 +7292,7 @@ ListTable.prototype.setData = function(rows) {
this.rows.forEach(function(row) { this.rows.forEach(function(row) {
row.forEach(function(cell, i) { row.forEach(function(cell, i) {
var clen = self._cellLength(cell); var clen = self.textLength(cell);
if (!maxes[i] || maxes[i] < clen + self.pad) { if (!maxes[i] || maxes[i] < clen + self.pad) {
maxes[i] = clen + self.pad; maxes[i] = clen + self.pad;
} }
@ -7313,7 +7313,7 @@ ListTable.prototype.setData = function(rows) {
var text = ''; var text = '';
row.forEach(function(cell, i) { row.forEach(function(cell, i) {
var width = maxes[i]; var width = maxes[i];
var clen = self._cellLength(cell); var clen = self.textLength(cell);
if (i !== 0) { if (i !== 0) {
text += ' '; text += ' ';
@ -7370,13 +7370,6 @@ ListTable.prototype.select = function(i) {
return this._select(i); return this._select(i);
}; };
ListTable.prototype._cellLength = function(text) {
if (!this.options.tags && !this.options.parseTags) {
return text.length;
}
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length;
};
ListTable.prototype.render = function() { ListTable.prototype.render = function() {
var self = this; var self = this;