mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 17:08:31 +01:00
chg: Removed redundant code = code.replace
This commit is contained in:
parent
dcac64fb9a
commit
bce0950498
1 changed files with 18 additions and 23 deletions
|
@ -257,29 +257,24 @@ const Code = {
|
|||
}
|
||||
|
||||
// Add strategic spaces
|
||||
code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ");
|
||||
code = code.replace(/\s*<([=]?)\s*/g, " <$1 ");
|
||||
code = code.replace(/\s*>([=]?)\s*/g, " >$1 ");
|
||||
code = code.replace(/([^+])\+([^+=])/g, "$1 + $2");
|
||||
code = code.replace(/([^-])-([^-=])/g, "$1 - $2");
|
||||
code = code.replace(/([^*])\*([^*=])/g, "$1 * $2");
|
||||
code = code.replace(/([^/])\/([^/=])/g, "$1 / $2");
|
||||
code = code.replace(/\s*,\s*/g, ", ");
|
||||
code = code.replace(/\s*{/g, " {");
|
||||
code = code.replace(/}\n/g, "}\n\n");
|
||||
|
||||
// Just... don't look at this
|
||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3");
|
||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3");
|
||||
code = code.replace(/else\s*\n([^{])/gim, "else\n $1");
|
||||
code = code.replace(/else\s+([^{])/gim, "else $1");
|
||||
|
||||
// Remove strategic spaces
|
||||
code = code.replace(/\s+;/g, ";");
|
||||
code = code.replace(/\{\s+\}/g, "{}");
|
||||
code = code.replace(/\[\s+\]/g, "[]");
|
||||
code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
|
||||
|
||||
code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ")
|
||||
.replace(/\s*<([=]?)\s*/g, " <$1 ")
|
||||
.replace(/\s*>([=]?)\s*/g, " >$1 ")
|
||||
.replace(/([^+])\+([^+=])/g, "$1 + $2")
|
||||
.replace(/([^-])-([^-=])/g, "$1 - $2")
|
||||
.replace(/([^*])\*([^*=])/g, "$1 * $2")
|
||||
.replace(/([^/])\/([^/=])/g, "$1 / $2")
|
||||
.replace(/\s*,\s*/g, ", ")
|
||||
.replace(/\s*{/g, " {")
|
||||
.replace(/}\n/g, "}\n\n")
|
||||
.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3")
|
||||
.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3")
|
||||
.replace(/else\s*\n([^{])/gim, "else\n $1")
|
||||
.replace(/else\s+([^{])/gim, "else $1")
|
||||
.replace(/\s+;/g, ";")
|
||||
.replace(/\{\s+\}/g, "{}")
|
||||
.replace(/\[\s+\]/g, "[]")
|
||||
.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
|
||||
|
||||
// Replace preserved tokens
|
||||
var ptokens = /###preservedToken(\d+)###/g;
|
||||
|
|
Loading…
Reference in a new issue