small cleanup

This commit is contained in:
nightwing 2013-01-11 16:38:39 +04:00
commit 2894ecdb40
2 changed files with 11 additions and 12 deletions

View file

@ -37,13 +37,12 @@ exports.stringReverse = function(string) {
exports.stringRepeat = function (string, count) { exports.stringRepeat = function (string, count) {
var result = ''; var result = '';
while (count) while (count > 0) {
{
if (count & 1) if (count & 1)
result += string; result += string;
if (count >>= 1) if (count >>= 1)
string += string; string += string;
} }
return result; return result;
}; };

View file

@ -780,23 +780,23 @@ var Editor = require("./editor").Editor;
return m; return m;
}).map(isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign); }).map(isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
function strRepeat(n, ch) { function spaces(n) {
return Array(n + 1).join(ch) return lang.stringRepeat(" ", n);
} }
function alignLeft(m) { function alignLeft(m) {
return !m[2] ? m[0] : strRepeat(startW, " ") + m[2] return !m[2] ? m[0] : spaces(startW) + m[2]
+ strRepeat(textW - m[2].length + endW, " ") + spaces(textW - m[2].length + endW)
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ")
} }
function alignRight(m) { function alignRight(m) {
return !m[2] ? m[0] : strRepeat(startW + textW - m[2].length, " ") + m[2] return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
+ strRepeat(endW, " ") + spaces(endW, " ")
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ")
} }
function unAlign(m) { function unAlign(m) {
return !m[2] ? m[0] : strRepeat(startW, " ") + m[2] return !m[2] ? m[0] : spaces(startW) + m[2]
+ strRepeat(endW, " ") + spaces(endW)
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ")
} }
} }