Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function.prototype.method = function (name, func) {
- this.prototype[name] = func;
- return this;
- };
- String.method('deentityify', function () {
- // The entity table. It maps entity names to
- // characters.
- var entity = {
- quot: '"',
- lt: '<',
- gt: '>'
- };
- return function () {
- // This is the deentityify method. It calls the string
- // replace method, looking for substrings that start
- // with '&' and end with ';'. If the characters in
- // between are in the entity table, then replace the
- // entity with the character from the table. It uses
- // a regular expression (Chapter 7).
- return this.replace(/&([^&;]+);/g,
- function (a, b) {
- var r = entity[b];
- return typeof r === 'string' ? r : a;
- }
- );
- };
- }());
- '<">'.deentityify()
- String.method('deentityify', function () {
- // The entity table. It maps entity names to
- // characters.
- var entity = {
- quot: '"',
- lt: '<',
- gt: '>'
- };
- return function () {
- // This is the deentityify method. It calls the string
- // replace method, looking for substrings that start
- // with '&' and end with ';'. If the characters in
- // between are in the entity table, then replace the
- // entity with the character from the table. It uses
- // a regular expression (Chapter 7).
- return this.replace(/&([^&;]+);/g,
- function (a, b) {
- var r = entity[b];
- return typeof r === 'string' ? r : a;
- }
- );
- };
- }());
- 'any string'.deentityfy()
- String.deentityfy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement