[ Index ] |
PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10) |
[Summary view] [Print] [Text view]
1 /* 2 --- 3 4 script: String.Extras.js 5 6 name: String.Extras 7 8 description: Extends the String native object to include methods useful in managing various kinds of strings (query strings, urls, html, etc). 9 10 license: MIT-style license 11 12 authors: 13 - Aaron Newton 14 - Guillermo Rauch 15 - Christopher Pitt 16 17 requires: 18 - Core/String 19 - Core/$util 20 - Core/Array 21 22 provides: [String.Extras] 23 24 ... 25 */ 26 27 (function(){ 28 29 var special = { 30 'a': '[àáâãäåăą]', 31 'A': '[ÀÁÂÃÄÅĂĄ]', 32 'c': '[ćčç]', 33 'C': '[ĆČÇ]', 34 'd': '[ďđ]', 35 'D': '[ĎÐ]', 36 'e': '[èéêëěę]', 37 'E': '[ÈÉÊËĚĘ]', 38 'g': '[ğ]', 39 'G': '[Ğ]', 40 'i': '[ìíîï]', 41 'I': '[ÌÍÎÏ]', 42 'l': '[ĺľł]', 43 'L': '[ĹĽŁ]', 44 'n': '[ñňń]', 45 'N': '[ÑŇŃ]', 46 'o': '[òóôõöøő]', 47 'O': '[ÒÓÔÕÖØ]', 48 'r': '[řŕ]', 49 'R': '[ŘŔ]', 50 's': '[ššş]', 51 'S': '[ŠŞŚ]', 52 't': '[ťţ]', 53 'T': '[ŤŢ]', 54 'ue': '[ü]', 55 'UE': '[Ü]', 56 'u': '[ùúûůµ]', 57 'U': '[ÙÚÛŮ]', 58 'y': '[ÿý]', 59 'Y': '[ŸÝ]', 60 'z': '[žźż]', 61 'Z': '[ŽŹŻ]', 62 'th': '[þ]', 63 'TH': '[Þ]', 64 'dh': '[ð]', 65 'DH': '[Ð]', 66 'ss': '[ß]', 67 'oe': '[œ]', 68 'OE': '[Œ]', 69 'ae': '[æ]', 70 'AE': '[Æ]' 71 }, 72 73 tidy = { 74 ' ': '[\xa0\u2002\u2003\u2009]', 75 '*': '[\xb7]', 76 '\'': '[\u2018\u2019]', 77 '"': '[\u201c\u201d]', 78 '...': '[\u2026]', 79 '-': '[\u2013]', 80 '--': '[\u2014]', 81 '»': '[\uFFFD]' 82 }; 83 84 function walk(string, replacements) { 85 var result = string; 86 87 for (key in replacements) { 88 result = result.replace(new RegExp(replacements[key], 'g'), key); 89 } 90 91 return result; 92 } 93 94 function getRegForTag(tag, contents) { 95 tag = tag || ''; 96 var regstr = contents ? "<" + tag + "(?!\\w)[^>]*>([\\s\\S]*?)<\/" + tag + "(?!\\w)>" : "<\/?" + tag + "([^>]+)?>"; 97 reg = new RegExp(regstr, "gi"); 98 return reg; 99 }; 100 101 String.implement({ 102 103 standardize: function(){ 104 return walk(this, special); 105 }, 106 107 repeat: function(times){ 108 return new Array(times + 1).join(this); 109 }, 110 111 pad: function(length, str, dir){ 112 if (this.length >= length) return this; 113 var pad = (str == null ? ' ' : '' + str).repeat(length - this.length).substr(0, length - this.length); 114 if (!dir || dir == 'right') return this + pad; 115 if (dir == 'left') return pad + this; 116 return pad.substr(0, (pad.length / 2).floor()) + this + pad.substr(0, (pad.length / 2).ceil()); 117 }, 118 119 getTags: function(tag, contents){ 120 return this.match(getRegForTag(tag, contents)) || []; 121 }, 122 123 stripTags: function(tag, contents){ 124 return this.replace(getRegForTag(tag, contents), ''); 125 }, 126 127 tidy: function(){ 128 return walk(this, tidy); 129 } 130 131 }); 132 133 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 16 22:51:00 2010 | Cross-referenced by PHPXref 0.7 |