diff options
Diffstat (limited to 'lib/utils.js')
-rw-r--r-- | lib/utils.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/utils.js b/lib/utils.js index 585c4fced..69e2b78bc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -90,7 +90,7 @@ exports.padRight = padRight; function trimRight(name) { var l = name.length; - while (l > 0 && name[l-1] === ' ') l -= 1; + while (l > 0 && name[l - 1] === ' ') l -= 1; return name.substr(0, l); } @@ -107,8 +107,7 @@ exports.trimRight = trimRight; exports.anonymizeIp = function anonymizeIp(ip) { if (ip.includes('localhost')) { return ip; - } - else if (ip.includes(':')) { + } else if (ip.includes(':')) { // IPv6 return ip.replace(/:[\da-fA-F]{0,4}:[\da-fA-F]{0,4}:[\da-fA-F]{0,4}$/, ':0:0:0'); } else { @@ -119,7 +118,7 @@ exports.anonymizeIp = function anonymizeIp(ip) { function objectToHashableString(object) { // See https://stackoverflow.com/questions/899574/which-is-best-to-use-typeof-or-instanceof/6625960#6625960 - return (typeof(object) === 'string') ? object : JSON.stringify(object); + return (typeof (object) === 'string') ? object : JSON.stringify(object); } const DefaultHash = 'Compiler Explorer Default Version 1'; @@ -177,12 +176,13 @@ exports.glGetMainContents = function glGetMainContents(content) { return contents; }; -function trimLine(line) { +function squashHorizontalWhitespace(line, atStart) { + if (atStart === undefined) atStart = true; if (!line.trim().length) { return ""; } const splat = line.split(/\s+/); - if (splat[0] === "") { + if (splat[0] === "" && atStart) { // An indented line: preserve a two-space indent (max) const intent = line[1] !== " " ? " " : " "; return intent + splat.slice(1).join(" "); @@ -190,4 +190,4 @@ function trimLine(line) { return splat.join(" "); } -exports.trimLine = trimLine; +exports.squashHorizontalWhitespace = squashHorizontalWhitespace; |