Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Module to contain logic for fixing characters.
- var FigureFixer = {
- Map: { }, // Holds character/code pairs
- // Adds a character/code pairing, where the "code"
- // is the escaped string and the "character" is the
- // character that should replace it.
- add: function(code, character) {
- FigureFixer.Map[code] = character;
- },
- // Iterate through the code/characters added and replace
- // each, then return the string.
- parse: function(string) {
- for (code in FigureFixer.Map)
- string.replace(code, FigureFixer[code]);
- return string;
- }
- }
- // Add a simple method to strings for fixing characters
- String.prototype.fixCharacters = function() {
- return FigureFixer.parse(this);
- }
- // Add character/code pair
- FigureFixer.add("\u0026", '&');
- // Create a test string
- var TEST_STRING = "This \u0026 That";
- // Call string method
- TEST_STRING.fixCharacters();
- // View result
- print(TEST_STRING); // => This & That
Add Comment
Please, Sign In to add comment