1 | define(["dojo/_base/lang"], function(lang) { |
---|
2 | // dojox.html.entities.html [public] Array |
---|
3 | // Entity characters for HTML, represented as an array of |
---|
4 | // character code, entity name (minus & and ; wrapping. |
---|
5 | // The function wrapper is to fix global leking with the build tools. |
---|
6 | var dhe = lang.getObject("dojox.html.entities",true); |
---|
7 | |
---|
8 | var _applyEncodingMap = function(str, map){ |
---|
9 | // summary: |
---|
10 | // Private internal function for performing encoding of entity characters. |
---|
11 | // tags: |
---|
12 | // private |
---|
13 | |
---|
14 | // Check to see if we have genned and cached a regexp for this map yet |
---|
15 | // If we have, use it, if not, gen it, cache, then use. |
---|
16 | var mapper, regexp; |
---|
17 | if(map._encCache && |
---|
18 | map._encCache.regexp && |
---|
19 | map._encCache.mapper && |
---|
20 | map.length == map._encCache.length){ |
---|
21 | mapper = map._encCache.mapper; |
---|
22 | regexp = map._encCache.regexp; |
---|
23 | }else{ |
---|
24 | mapper = {}; |
---|
25 | regexp = ["["]; |
---|
26 | var i; |
---|
27 | for(i = 0; i < map.length; i++){ |
---|
28 | mapper[map[i][0]] = "&" + map[i][1] + ";"; |
---|
29 | regexp.push(map[i][0]); |
---|
30 | } |
---|
31 | regexp.push("]"); |
---|
32 | regexp = new RegExp(regexp.join(""), "g"); |
---|
33 | map._encCache = { |
---|
34 | mapper: mapper, |
---|
35 | regexp: regexp, |
---|
36 | length: map.length |
---|
37 | }; |
---|
38 | } |
---|
39 | str = str.replace(regexp, function(c){ |
---|
40 | return mapper[c]; |
---|
41 | }); |
---|
42 | return str; |
---|
43 | }; |
---|
44 | |
---|
45 | var _applyDecodingMap = function(str, map){ |
---|
46 | // summary: |
---|
47 | // Private internal function for performing decoding of entity characters. |
---|
48 | // tags: |
---|
49 | // private |
---|
50 | var mapper, regexp; |
---|
51 | if(map._decCache && |
---|
52 | map._decCache.regexp && |
---|
53 | map._decCache.mapper && |
---|
54 | map.length == map._decCache.length){ |
---|
55 | mapper = map._decCache.mapper; |
---|
56 | regexp = map._decCache.regexp; |
---|
57 | }else{ |
---|
58 | mapper = {}; |
---|
59 | regexp = ["("]; |
---|
60 | var i; |
---|
61 | for(i = 0; i < map.length; i++){ |
---|
62 | var e = "&" + map[i][1] + ";"; |
---|
63 | if(i){regexp.push("|");} |
---|
64 | mapper[e] = map[i][0]; |
---|
65 | regexp.push(e); |
---|
66 | } |
---|
67 | regexp.push(")"); |
---|
68 | regexp = new RegExp(regexp.join(""), "g"); |
---|
69 | map._decCache = { |
---|
70 | mapper: mapper, |
---|
71 | regexp: regexp, |
---|
72 | length: map.length |
---|
73 | }; |
---|
74 | } |
---|
75 | str = str.replace(regexp, function(c){ |
---|
76 | return mapper[c]; |
---|
77 | }); |
---|
78 | return str; |
---|
79 | }; |
---|
80 | |
---|
81 | dhe.html = [ |
---|
82 | ["\u0026","amp"], ["\u0022","quot"],["\u003C","lt"], ["\u003E","gt"], |
---|
83 | ["\u00A0","nbsp"] |
---|
84 | ]; |
---|
85 | |
---|
86 | // dojox.html.entities.latin [public] Array |
---|
87 | // Entity characters for Latin characters and similar, represented as an array of |
---|
88 | // character code, entity name (minus & and ; wrapping. |
---|
89 | dhe.latin = [ |
---|
90 | ["\u00A1","iexcl"],["\u00A2","cent"],["\u00A3","pound"],["\u20AC","euro"], |
---|
91 | ["\u00A4","curren"],["\u00A5","yen"],["\u00A6","brvbar"],["\u00A7","sect"], |
---|
92 | ["\u00A8","uml"],["\u00A9","copy"],["\u00AA","ordf"],["\u00AB","laquo"], |
---|
93 | ["\u00AC","not"],["\u00AD","shy"],["\u00AE","reg"],["\u00AF","macr"], |
---|
94 | ["\u00B0","deg"],["\u00B1","plusmn"],["\u00B2","sup2"],["\u00B3","sup3"], |
---|
95 | ["\u00B4","acute"],["\u00B5","micro"],["\u00B6","para"],["\u00B7","middot"], |
---|
96 | ["\u00B8","cedil"],["\u00B9","sup1"],["\u00BA","ordm"],["\u00BB","raquo"], |
---|
97 | ["\u00BC","frac14"],["\u00BD","frac12"],["\u00BE","frac34"],["\u00BF","iquest"], |
---|
98 | ["\u00C0","Agrave"],["\u00C1","Aacute"],["\u00C2","Acirc"],["\u00C3","Atilde"], |
---|
99 | ["\u00C4","Auml"],["\u00C5","Aring"],["\u00C6","AElig"],["\u00C7","Ccedil"], |
---|
100 | ["\u00C8","Egrave"],["\u00C9","Eacute"],["\u00CA","Ecirc"],["\u00CB","Euml"], |
---|
101 | ["\u00CC","Igrave"],["\u00CD","Iacute"],["\u00CE","Icirc"],["\u00CF","Iuml"], |
---|
102 | ["\u00D0","ETH"],["\u00D1","Ntilde"],["\u00D2","Ograve"],["\u00D3","Oacute"], |
---|
103 | ["\u00D4","Ocirc"],["\u00D5","Otilde"],["\u00D6","Ouml"],["\u00D7","times"], |
---|
104 | ["\u00D8","Oslash"],["\u00D9","Ugrave"],["\u00DA","Uacute"],["\u00DB","Ucirc"], |
---|
105 | ["\u00DC","Uuml"],["\u00DD","Yacute"],["\u00DE","THORN"],["\u00DF","szlig"], |
---|
106 | ["\u00E0","agrave"],["\u00E1","aacute"],["\u00E2","acirc"],["\u00E3","atilde"], |
---|
107 | ["\u00E4","auml"],["\u00E5","aring"],["\u00E6","aelig"],["\u00E7","ccedil"], |
---|
108 | ["\u00E8","egrave"],["\u00E9","eacute"],["\u00EA","ecirc"],["\u00EB","euml"], |
---|
109 | ["\u00EC","igrave"],["\u00ED","iacute"],["\u00EE","icirc"],["\u00EF","iuml"], |
---|
110 | ["\u00F0","eth"],["\u00F1","ntilde"],["\u00F2","ograve"],["\u00F3","oacute"], |
---|
111 | ["\u00F4","ocirc"],["\u00F5","otilde"],["\u00F6","ouml"],["\u00F7","divide"], |
---|
112 | ["\u00F8","oslash"],["\u00F9","ugrave"],["\u00FA","uacute"],["\u00FB","ucirc"], |
---|
113 | ["\u00FC","uuml"],["\u00FD","yacute"],["\u00FE","thorn"],["\u00FF","yuml"], |
---|
114 | ["\u0192","fnof"],["\u0391","Alpha"],["\u0392","Beta"],["\u0393","Gamma"], |
---|
115 | ["\u0394","Delta"],["\u0395","Epsilon"],["\u0396","Zeta"],["\u0397","Eta"], |
---|
116 | ["\u0398","Theta"], ["\u0399","Iota"],["\u039A","Kappa"],["\u039B","Lambda"], |
---|
117 | ["\u039C","Mu"],["\u039D","Nu"],["\u039E","Xi"],["\u039F","Omicron"], |
---|
118 | ["\u03A0","Pi"],["\u03A1","Rho"],["\u03A3","Sigma"],["\u03A4","Tau"], |
---|
119 | ["\u03A5","Upsilon"],["\u03A6","Phi"],["\u03A7","Chi"],["\u03A8","Psi"], |
---|
120 | ["\u03A9","Omega"],["\u03B1","alpha"],["\u03B2","beta"],["\u03B3","gamma"], |
---|
121 | ["\u03B4","delta"],["\u03B5","epsilon"],["\u03B6","zeta"],["\u03B7","eta"], |
---|
122 | ["\u03B8","theta"],["\u03B9","iota"],["\u03BA","kappa"],["\u03BB","lambda"], |
---|
123 | ["\u03BC","mu"],["\u03BD","nu"],["\u03BE","xi"],["\u03BF","omicron"], |
---|
124 | ["\u03C0","pi"],["\u03C1","rho"],["\u03C2","sigmaf"],["\u03C3","sigma"], |
---|
125 | ["\u03C4","tau"],["\u03C5","upsilon"],["\u03C6","phi"],["\u03C7","chi"], |
---|
126 | ["\u03C8","psi"],["\u03C9","omega"],["\u03D1","thetasym"],["\u03D2","upsih"], |
---|
127 | ["\u03D6","piv"],["\u2022","bull"],["\u2026","hellip"],["\u2032","prime"], |
---|
128 | ["\u2033","Prime"],["\u203E","oline"],["\u2044","frasl"],["\u2118","weierp"], |
---|
129 | ["\u2111","image"],["\u211C","real"],["\u2122","trade"],["\u2135","alefsym"], |
---|
130 | ["\u2190","larr"],["\u2191","uarr"],["\u2192","rarr"],["\u2193","darr"], |
---|
131 | ["\u2194","harr"],["\u21B5","crarr"],["\u21D0","lArr"],["\u21D1","uArr"], |
---|
132 | ["\u21D2","rArr"],["\u21D3","dArr"],["\u21D4","hArr"],["\u2200","forall"], |
---|
133 | ["\u2202","part"],["\u2203","exist"],["\u2205","empty"],["\u2207","nabla"], |
---|
134 | ["\u2208","isin"],["\u2209","notin"],["\u220B","ni"],["\u220F","prod"], |
---|
135 | ["\u2211","sum"],["\u2212","minus"],["\u2217","lowast"],["\u221A","radic"], |
---|
136 | ["\u221D","prop"],["\u221E","infin"],["\u2220","ang"],["\u2227","and"], |
---|
137 | ["\u2228","or"],["\u2229","cap"],["\u222A","cup"],["\u222B","int"], |
---|
138 | ["\u2234","there4"],["\u223C","sim"],["\u2245","cong"],["\u2248","asymp"], |
---|
139 | ["\u2260","ne"],["\u2261","equiv"],["\u2264","le"],["\u2265","ge"], |
---|
140 | ["\u2282","sub"],["\u2283","sup"],["\u2284","nsub"],["\u2286","sube"], |
---|
141 | ["\u2287","supe"],["\u2295","oplus"],["\u2297","otimes"],["\u22A5","perp"], |
---|
142 | ["\u22C5","sdot"],["\u2308","lceil"],["\u2309","rceil"],["\u230A","lfloor"], |
---|
143 | ["\u230B","rfloor"],["\u2329","lang"],["\u232A","rang"],["\u25CA","loz"], |
---|
144 | ["\u2660","spades"],["\u2663","clubs"],["\u2665","hearts"],["\u2666","diams"], |
---|
145 | ["\u0152","Elig"],["\u0153","oelig"],["\u0160","Scaron"],["\u0161","scaron"], |
---|
146 | ["\u0178","Yuml"],["\u02C6","circ"],["\u02DC","tilde"],["\u2002","ensp"], |
---|
147 | ["\u2003","emsp"],["\u2009","thinsp"],["\u200C","zwnj"],["\u200D","zwj"], |
---|
148 | ["\u200E","lrm"],["\u200F","rlm"],["\u2013","ndash"],["\u2014","mdash"], |
---|
149 | ["\u2018","lsquo"],["\u2019","rsquo"],["\u201A","sbquo"],["\u201C","ldquo"], |
---|
150 | ["\u201D","rdquo"],["\u201E","bdquo"],["\u2020","dagger"],["\u2021","Dagger"], |
---|
151 | ["\u2030","permil"],["\u2039","lsaquo"],["\u203A","rsaquo"] |
---|
152 | ]; |
---|
153 | |
---|
154 | dhe.encode = function(str/*string*/, m /*array?*/){ |
---|
155 | // summary: |
---|
156 | // Function to obtain an entity encoding for a specified character |
---|
157 | // str: |
---|
158 | // The string to process for possible entity encoding. |
---|
159 | // m: |
---|
160 | // An optional list of character to entity name mappings (array of |
---|
161 | // arrays). If not provided, it uses the and Latin entities as the |
---|
162 | // set to map and escape. |
---|
163 | // tags: |
---|
164 | // public |
---|
165 | if(str){ |
---|
166 | if(!m){ |
---|
167 | // Apply the basic mappings. HTML should always come first when decoding |
---|
168 | // as well. |
---|
169 | str = _applyEncodingMap(str, dhe.html); |
---|
170 | str = _applyEncodingMap(str, dhe.latin); |
---|
171 | |
---|
172 | }else{ |
---|
173 | str = _applyEncodingMap(str, m); |
---|
174 | } |
---|
175 | } |
---|
176 | return str; |
---|
177 | }; |
---|
178 | |
---|
179 | dhe.decode = function(str/*string*/, m /*array?*/){ |
---|
180 | // summary: |
---|
181 | // Function to obtain an entity encoding for a specified character |
---|
182 | // str: |
---|
183 | // The string to process for possible entity encoding to decode. |
---|
184 | // m: |
---|
185 | // An optional list of character to entity name mappings (array of |
---|
186 | // arrays). If not provided, it uses the HTML and Latin entities as the |
---|
187 | // set to map and decode. |
---|
188 | // tags: |
---|
189 | // public |
---|
190 | if(str){ |
---|
191 | if(!m){ |
---|
192 | // Apply the basic mappings. HTML should always come first when decoding |
---|
193 | // as well. |
---|
194 | str = _applyDecodingMap(str, dhe.html); |
---|
195 | str = _applyDecodingMap(str, dhe.latin); |
---|
196 | |
---|
197 | }else{ |
---|
198 | str = _applyDecodingMap(str, m); |
---|
199 | } |
---|
200 | } |
---|
201 | return str; |
---|
202 | }; |
---|
203 | return dhe; |
---|
204 | }); |
---|
205 | |
---|