Guest User

Untitled

a guest
Feb 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // Module to contain logic for fixing characters.
  2. var FigureFixer = {
  3. Map: { }, // Holds character/code pairs
  4.  
  5. // Adds a character/code pairing, where the "code"
  6. // is the escaped string and the "character" is the
  7. // character that should replace it.
  8. add: function(code, character) {
  9. FigureFixer.Map[code] = character;
  10. },
  11.  
  12. // Iterate through the code/characters added and replace
  13. // each, then return the string.
  14. parse: function(string) {
  15. for (code in FigureFixer.Map)
  16. string.replace(code, FigureFixer[code]);
  17. return string;
  18. }
  19. }
  20.  
  21. // Add a simple method to strings for fixing characters
  22. String.prototype.fixCharacters = function() {
  23. return FigureFixer.parse(this);
  24. }
  25.  
  26. // Add character/code pair
  27. FigureFixer.add("\u0026", '&');
  28.  
  29. // Create a test string
  30. var TEST_STRING = "This \u0026 That";
  31.  
  32. // Call string method
  33. TEST_STRING.fixCharacters();
  34.  
  35. // View result
  36. print(TEST_STRING); // => This & That
Add Comment
Please, Sign In to add comment