small cleanup
This commit is contained in:
parent
70f34b6b38
commit
2894ecdb40
2 changed files with 11 additions and 12 deletions
|
|
@ -37,8 +37,7 @@ 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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue