Skip to content

Instantly share code, notes, and snippets.

@appden
Created December 17, 2009 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appden/258897 to your computer and use it in GitHub Desktop.
Save appden/258897 to your computer and use it in GitHub Desktop.
// a suggestion to Objective-J for better performance
var HTMLEntities = {
'&': '&',
'"': '"',
"'": ''',
'<': '&lt;',
'>': '&gt;'
};
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