-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
83 lines (73 loc) · 3.5 KB
/
main.js
File metadata and controls
83 lines (73 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
document.onclick = function() {
let parent;
if (typeof getSelection().focusNode != "undefined") {
parent = getSelection().focusNode.parentElement;
if (typeof parent.tagName != "undefined" && parent.tagName == "CODE") {
navigator.clipboard.writeText(parent.innerText)
let child = document.createElement("div");
document.body.appendChild(child);
child.classList = "hovermsg";
child.innerText = "Copied!"
child.style.left = parent.offsetLeft - child.offsetWidth / 2 + parent.offsetWidth / 2;
child.style.top = parent.offsetTop - child.offsetHeight;
setTimeout(()=>child.remove(),2000)
}}
};
// obj->prop obj->method() same same emptyFn() fullFn(args)
function debugStringify(string, pres = ["Before: ", "After : "]) {
f = pre => {
let outputString = `std::cout<<"${pre}"`;
let arrowsAllowed = document.getElementById("arr").checked
let functionAllowed = document.getElementById("fn").checked
let notEmptyFunctionsAllowed = document.getElementById("nef").checked
let specialCharsAllowed = document.getElementById("spc").checked
let duplicatesAllowed = document.getElementById("dup").checked
let keywordsAllowed = document.getElementById("kwd").checked
// Remove the arrows
if (!arrowsAllowed) string = string
.replace(/[^ ]*->[^ ]*/g, " ")
if (!specialCharsAllowed) string = string
.replace(/[^a-zA-Z0-9\(\)\[\]\-\>äöüß]/g, " ")
.replace(/-[^>]/g, " ")
if (!functionAllowed) string = string
.replace(/[^ ]+\([^\)]*?\)/g,"")
if (!notEmptyFunctionsAllowed) string = string
.replace(/[^ ]*\([^\)]+?\)/g,"")
console.log(string)
string // method chain
.replace(/ /g, " ") // add multiple spaces together
.replace(/ [0-9][0-9a-zA-Z]*? /g, " ")
.replace(/[ ]+/g, " ") // add multiple spaces together
.replace(/^ /, "") // remove spaces @ the start
.replace(/ $/, "") // & the end
.split(" ")
.forEach(variable => {
if ((!outputString.includes(", "+variable+":") || duplicatesAllowed) && (!keywords.includes(variable) || keywordsAllowed)) {
outputString += `<<", ${variable}: "<<${variable}`
}
});
return outputString.replace(", ", "") + "<<\"\\n\";\n"
};
out = [];
pres.forEach(pre => out.push(f(pre)));
return out;
}
function p(example = false) {
let inputElement = document.getElementById("i")
let outputElement = document.getElementById("o")
i = inputElement.value.replace(/\n/g,"$");
if (example) {i = "BFOR: $AFTR: $position = position * variable"; outputElement = document.getElementById("generated")}
outputElement.innerHTML = "";
if (!i.includes("$")) {
debugStringify(i)
.forEach(text => outputElement.innerHTML += ("<code>" + text.replace(/\</g,"<") + "</code><br><br>"))
} else {
arr = i.split("$");
debugStringify(arr.splice(arr.length - 1, 1)[0], arr)
.forEach(text => outputElement.innerHTML += ("<code>" + text.replace(/\</g,"<") + "</code><br><br>"))
}
//if (!i.match(/[a-zA-Z]/) || !outputElement.innerText.match(/<<[a-zA-Z0-9]+<</)) outputElement.innerHTML = "<code>Output goes here...</code>";
}
function showExample() {
p(true);
}