small cleanup
This commit is contained in:
parent
70f34b6b38
commit
2894ecdb40
2 changed files with 11 additions and 12 deletions
|
|
@ -37,13 +37,12 @@ exports.stringReverse = function(string) {
|
|||
|
||||
exports.stringRepeat = function (string, count) {
|
||||
var result = '';
|
||||
while (count)
|
||||
{
|
||||
while (count > 0) {
|
||||
if (count & 1)
|
||||
result += string;
|
||||
result += string;
|
||||
|
||||
if (count >>= 1)
|
||||
string += string;
|
||||
string += string;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -780,23 +780,23 @@ var Editor = require("./editor").Editor;
|
|||
return m;
|
||||
}).map(isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign);
|
||||
|
||||
function strRepeat(n, ch) {
|
||||
return Array(n + 1).join(ch)
|
||||
function spaces(n) {
|
||||
return lang.stringRepeat(" ", n);
|
||||
}
|
||||
|
||||
function alignLeft(m) {
|
||||
return !m[2] ? m[0] : strRepeat(startW, " ") + m[2]
|
||||
+ strRepeat(textW - m[2].length + endW, " ")
|
||||
return !m[2] ? m[0] : spaces(startW) + m[2]
|
||||
+ spaces(textW - m[2].length + endW)
|
||||
+ m[4].replace(/^([=:])\s+/, "$1 ")
|
||||
}
|
||||
function alignRight(m) {
|
||||
return !m[2] ? m[0] : strRepeat(startW + textW - m[2].length, " ") + m[2]
|
||||
+ strRepeat(endW, " ")
|
||||
return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
|
||||
+ spaces(endW, " ")
|
||||
+ m[4].replace(/^([=:])\s+/, "$1 ")
|
||||
}
|
||||
function unAlign(m) {
|
||||
return !m[2] ? m[0] : strRepeat(startW, " ") + m[2]
|
||||
+ strRepeat(endW, " ")
|
||||
return !m[2] ? m[0] : spaces(startW) + m[2]
|
||||
+ spaces(endW)
|
||||
+ m[4].replace(/^([=:])\s+/, "$1 ")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue