Originally, I did some tests for removing the comment regex, and these were the results source code. The problem is with the comments, the parser is having problems as it's not expecting a comment. I believe parsing out the comments is the easiest solution.
Here is my solution to both tickets. souce and a test.
What I am doing is first, creating an array that contains all the strings.
Then, masking all the strings, this will also grab any strings inside a comment
// Saves all strings into an array
// masks all strings into <STRING n>
// to be replaced with the array strings later
var strings = aCode.match(/("|').*("|')/g);
for ( var i = 0; /("|').*("|')/.test(aCode); i++)
{
aCode = aCode.replace(/("|').*("|')/, "<STRING " + i + ">");
}
Then, I parse away all comments.
// Remove end-of-line comments
aCode = aCode.replace(/\/\/.*\n/g, "\n");
Any strings inside a comment do not matter, and any // inside a string have already been converted to
I then replace all the strings as the final step.
// replaces all masked strings from <STRING n> to the appropriate string
if (strings != null){
for( var i = 0; l = i < strings.length; i++ ){
var ex = new RegExp("\<STRING " + i + "\>");
aCode = aCode.replace(ex, strings[i]);
}
}
any strings that were removed because of being in a comment, are not replaced, and the program simply skips it.
I'm ready to upload it, and hope I have not missed anything as it's my first time! *fingers crossed*
Hi friends, its great post about cultureand completely explained,
ReplyDeletekeep it up all the time.
My webpage - http://paddolker.com