Created
December 17, 2009 17:42
-
-
Save appden/258897 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
// a suggestion to Objective-J for better performance | |
var HTMLEntities = { | |
'&': '&', | |
'"': '"', | |
"'": ''', | |
'<': '<', | |
'>': '>' | |
}; | |
for (var c in HTMLEntities) HTMLEntities[HTMLEntities[c]] = c; | |
var replacer = function(match){ | |
return HTMLEntities[match]; | |
}; | |
var _encodeHTMLComponent = function(aString){ | |
return aString.replace(/[&"'<>]/g, replacer); | |
}; | |
var _decodeHTMLComponent = function(aString){ | |
return aString.replace(/&(?:amp|quot|apos|lt|gt);/g, replacer); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment