Created
April 17, 2010 23:06
-
-
Save notmasteryet/369883 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<script type="text/javascript"> | |
(function () { | |
this.P = function() { | |
var r = []; for(var i=0;i<100000;++i) r.push(i); // fill memory | |
var aCode = 'String b = "Stringb";\n// "string" \n alert("b");'; | |
alert(P.parse(aCode)); | |
}; | |
P.parse = function(aCode) { | |
var strings = []; | |
aCode = aCode.replace(/(["'])(\\\1|.)*?(\1)/g, function(all) { | |
strings.push(all); | |
return "<STRING " + (strings.length - 1) + ">"; | |
}); | |
aCode = aCode.replace(/\/\/.*\n/g, "\n"); | |
// replaces all masked strings from <STRING n> to the appropriate string contained in the strings array | |
for (var n = 0; n < strings.length; n++) { | |
aCode = (function() { | |
return aCode.replace(new RegExp("(.*)(<STRING " + n + ">)(.*)", "g"), function(all, quoteStart, match, quoteEnd) { | |
var notString = true, | |
quoteType = "", | |
escape = false; | |
for (var x = 0; x < quoteStart.length; x++) { | |
if (notString) { | |
if (quoteStart.charAt(x) === "\"" || quoteStart.charAt(x) === "'") { | |
quoteType = quoteStart.charAt(x); | |
notString = false; | |
} | |
} else { | |
if (!escape) { | |
if (quoteStart.charAt(x) === "\\") { | |
escape = true; | |
} else if (quoteStart.charAt(x) === quoteType) { | |
notString = true; | |
quoteType = ""; | |
} | |
} else { | |
escape = false; | |
} | |
} | |
} | |
var r = []; for(var i=0;i<10000;++i) r.push(i); // fill memory | |
if (notString) { | |
return quoteStart + strings[n] + quoteEnd; | |
} else { | |
return all; | |
} | |
}); | |
}()); | |
} | |
return aCode; | |
}; | |
var init = function() { | |
P(); | |
}; | |
document.addEventListener('DOMContentLoaded', function() { | |
init(); | |
}, false); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix for Minefield:
Line 26: aCode = (function(strings) {
Line 61: }(strings));