aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
authorMatt Godbolt <matt@godbolt.org>2019-03-21 20:48:53 -0500
committerGitHub <noreply@github.com>2019-03-21 20:48:53 -0500
commit43e24cb00d13cd443c34b27c67ec76cbe96b37fd (patch)
tree387ffc9ba2487bea8c6ab9eb7c40d03cd1e74dc6 /lib/utils.js
parenta47efe6d65f86024f46be5ef96139bb2f67dca73 (diff)
parentb87322568ed7f73a8583cdce707f68f07a0995dd (diff)
downloadcompiler-explorer-43e24cb00d13cd443c34b27c67ec76cbe96b37fd.tar.gz
compiler-explorer-43e24cb00d13cd443c34b27c67ec76cbe96b37fd.zip
Merge pull request #992 from bugwelle/llvm
[LLVM] Implement PoC llvm ir highlighting
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 8af638d3c..585c4fced 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -29,6 +29,7 @@ const tabsRe = /\t/g;
const lineRe = /\r?\n/;
function splitLines(text) {
+ if (!text) return [];
const result = text.split(lineRe);
if (result.length > 0 && result[result.length - 1] === '')
return result.slice(0, result.length - 1);
@@ -175,3 +176,18 @@ exports.glGetMainContents = function glGetMainContents(content) {
});
return contents;
};
+
+function trimLine(line) {
+ if (!line.trim().length) {
+ return "";
+ }
+ const splat = line.split(/\s+/);
+ if (splat[0] === "") {
+ // An indented line: preserve a two-space indent (max)
+ const intent = line[1] !== " " ? " " : " ";
+ return intent + splat.slice(1).join(" ");
+ }
+ return splat.join(" ");
+}
+
+exports.trimLine = trimLine;