Skip to content
This repository
Newer
Older
100644 737 lines (684 sloc) 26.651 kb
cb449bb9 »
2011-01-10 Added Project Files
1 //
2 // NSString+HTML.m
3 // CoreTextExtensions
4 //
5 // Created by Oliver Drobnik on 1/9/11.
5170e1a0 »
2011-01-10 Changed License and yourcompanyname to Drobnik.com
6 // Copyright 2011 Drobnik.com. All rights reserved.
cb449bb9 »
2011-01-10 Added Project Files
7 //
8
9 #import "NSString+HTML.h"
afd603b4 »
2012-01-31 Mac Compatibility Mode: for Mac based UnitTest to compare generated o…
10 #import "DTCoreText.h"
11
cb449bb9 »
2011-01-10 Added Project Files
12
b9c51761 »
2011-01-18 Added HTML entity decoding
13 static NSDictionary *entityLookup = nil;
64101f15 »
2011-08-28 Added HTML entity encoding for strings, improved output of text attac…
14 static NSDictionary *entityReverseLookup = nil;
4d6189b3 » soffes
2011-01-13 Improve inline tag category
15
cb449bb9 »
2011-01-10 Added Project Files
16 @implementation NSString (HTML)
17
45551f09 »
2011-03-30 faster hex functions for HTML colors, courtesy of KPM
18 - (NSUInteger)integerValueFromHex
cb449bb9 »
2011-01-10 Added Project Files
19 {
01d8e799 »
2012-09-10 Fixed some warnings when running Mac Unit Test in Xcode 4.5
20 int result = 0;
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
21 sscanf([self UTF8String], "%x", &result);
22 return result;
cb449bb9 »
2011-01-10 Added Project Files
23 }
24
de39082b »
2011-04-15 Support for line-height CSS attribute
25 - (BOOL)isNumeric
26 {
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
27 const char *s = [self UTF8String];
28
06980a28 » dhoerl18
2011-12-02 Debug a retain cycle; moved ivars to implementation; cleared all warn…
29 for (size_t i=0;i<strlen(s);i++)
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
30 {
1e510997 »
2011-12-05 fixed isNumeric (thanks dzamir) - would break lineHeight
31 if ((s[i]<'0' || s[i]>'9') && (s[i] != '.'))
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
32 {
33 return NO;
34 }
35 }
36
37 return YES;
1cb06b5b »
2011-05-28 Fixes for line-height issues.
38 }
de39082b »
2011-04-15 Support for line-height CSS attribute
39
1cb06b5b »
2011-05-28 Fixes for line-height issues.
40 - (float)percentValue
41 {
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
42 float result = 1;
43 sscanf([self UTF8String], "%f", &result);
44
06980a28 » dhoerl18
2011-12-02 Debug a retain cycle; moved ivars to implementation; cleared all warn…
45 return result/100.0f;
de39082b »
2011-04-15 Support for line-height CSS attribute
46 }
47
7c412480 »
2011-01-17 Added whitespace normalization
48 - (NSString *)stringByNormalizingWhitespace
49 {
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
50 NSInteger stringLength = [self length];
51
52 // reserve buffer, same size as input
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
53 unichar *_characters = calloc(stringLength, sizeof(unichar));
54 [self getCharacters:_characters range:NSMakeRange(0, stringLength)];
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
55
56 NSInteger outputLength = 0;
57 BOOL inWhite = NO;
58
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
59
60 // we output to the same buffer as the input was
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
61 for (NSInteger i = 0; i<stringLength; i++)
62 {
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
63 // c-array access is faster because it saves objc calls
64 unichar oneChar = _characters[i]; // [self characterAtIndex:i];
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
65
66 // of whitespace chars only output one space for first
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
67 if (IS_WHITESPACE(oneChar))
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
68 {
69 if (!inWhite)
70 {
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
71 _characters[outputLength] = 32;
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
72 outputLength++;
73
74 inWhite = YES;
75 }
76 }
77 else
78 {
79 // all other characters we simply copy
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
80 _characters[outputLength] = oneChar;
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
81 outputLength++;
82
83 inWhite = NO;
84 }
85 }
86
87 // convert to objC-String
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
88 NSString *retString = [NSString stringWithCharacters:_characters length:outputLength];
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
89
90 // free buffers
c883070a »
2012-01-29 change whitespace compressor to in-place to save on objc calls
91 free(_characters);
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
92
93 return retString;
7c412480 »
2011-01-17 Added whitespace normalization
94 }
95
96 - (BOOL)hasPrefixCharacterFromSet:(NSCharacterSet *)characterSet
97 {
98 if (![self length])
99 {
100 return NO;
101 }
102
103 unichar firstChar = [self characterAtIndex:0];
104
105 return [characterSet characterIsMember:firstChar];
106 }
107
03ad066c »
2011-01-26 Fix for line beginning with space after newline
108 - (BOOL)hasSuffixCharacterFromSet:(NSCharacterSet *)characterSet
109 {
110 if (![self length])
111 {
112 return NO;
113 }
114
115 unichar lastChar = [self characterAtIndex:[self length]-1];
116
117 return [characterSet characterIsMember:lastChar];
118 }
119
64101f15 »
2011-08-28 Added HTML entity encoding for strings, improved output of text attac…
120
121 - (NSString *)stringByAddingHTMLEntities
122 {
123 static dispatch_once_t predicate;
7f42dff2 »
2011-09-14 Fixed crash on 3.2, removed duplicate lines of code
124
c967589a » dhoerl
2011-11-21 Fixed up project so it would build (removed dependencies on DTWebArch…
125 dispatch_once(&predicate, ^{
64101f15 »
2011-08-28 Added HTML entity encoding for strings, improved output of text attac…
126 entityReverseLookup = [[NSDictionary alloc] initWithObjectsAndKeys:@"&quot;", [NSNumber numberWithInteger:0x22],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
127 @"&amp;", [NSNumber numberWithInteger:0x26],
128 @"&apos;", [NSNumber numberWithInteger:0x27],
129 @"&lt;", [NSNumber numberWithInteger:0x3c],
130 @"&gt;", [NSNumber numberWithInteger:0x3e],
131 @"&nbsp;", [NSNumber numberWithInteger:0x00a0],
132 @"&iexcl;", [NSNumber numberWithInteger:0x00a1],
133 @"&cent;", [NSNumber numberWithInteger:0x00a2],
134 @"&pound;", [NSNumber numberWithInteger:0x00a3],
135 @"&curren;", [NSNumber numberWithInteger:0x00a4],
136 @"&yen;", [NSNumber numberWithInteger:0x00a5],
137 @"&brvbar;", [NSNumber numberWithInteger:0x00a6],
138 @"&sect;", [NSNumber numberWithInteger:0x00a7],
139 @"&uml;", [NSNumber numberWithInteger:0x00a8],
140 @"&copy;", [NSNumber numberWithInteger:0x00a9],
141 @"&ordf;", [NSNumber numberWithInteger:0x00aa],
142 @"&laquo;", [NSNumber numberWithInteger:0x00ab],
143 @"&not;", [NSNumber numberWithInteger:0x00ac],
144 @"&reg;", [NSNumber numberWithInteger:0x00ae],
145 @"&macr;", [NSNumber numberWithInteger:0x00af],
146 @"&deg;", [NSNumber numberWithInteger:0x00b0],
147 @"&plusmn;", [NSNumber numberWithInteger:0x00b1],
148 @"&sup2;", [NSNumber numberWithInteger:0x00b2],
149 @"&sup3;", [NSNumber numberWithInteger:0x00b3],
150 @"&acute;", [NSNumber numberWithInteger:0x00b4],
151 @"&micro;", [NSNumber numberWithInteger:0x00b5],
152 @"&para;", [NSNumber numberWithInteger:0x00b6],
153 @"&middot;", [NSNumber numberWithInteger:0x00b7],
154 @"&cedil;", [NSNumber numberWithInteger:0x00b8],
155 @"&sup1;", [NSNumber numberWithInteger:0x00b9],
156 @"&ordm;", [NSNumber numberWithInteger:0x00ba],
157 @"&raquo;", [NSNumber numberWithInteger:0x00bb],
158 @"&frac14;", [NSNumber numberWithInteger:0x00bc],
159 @"&frac12;", [NSNumber numberWithInteger:0x00bd],
160 @"&frac34;", [NSNumber numberWithInteger:0x00be],
161 @"&iquest;", [NSNumber numberWithInteger:0x00bf],
162 @"&Agrave;", [NSNumber numberWithInteger:0x00c0],
163 @"&Aacute;", [NSNumber numberWithInteger:0x00c1],
164 @"&Acirc;", [NSNumber numberWithInteger:0x00c2],
165 @"&Atilde;", [NSNumber numberWithInteger:0x00c3],
166 @"&Auml;", [NSNumber numberWithInteger:0x00c4],
167 @"&Aring;", [NSNumber numberWithInteger:0x00c5],
168 @"&AElig;", [NSNumber numberWithInteger:0x00c6],
169 @"&Ccedil;", [NSNumber numberWithInteger:0x00c7],
170 @"&Egrave;", [NSNumber numberWithInteger:0x00c8],
171 @"&Eacute;", [NSNumber numberWithInteger:0x00c9],
172 @"&Ecirc;", [NSNumber numberWithInteger:0x00ca],
173 @"&Euml;", [NSNumber numberWithInteger:0x00cb],
174 @"&Igrave;", [NSNumber numberWithInteger:0x00cc],
175 @"&Iacute;", [NSNumber numberWithInteger:0x00cd],
176 @"&Icirc;", [NSNumber numberWithInteger:0x00ce],
177 @"&Iuml;", [NSNumber numberWithInteger:0x00cf],
178 @"&ETH;", [NSNumber numberWithInteger:0x00d0],
179 @"&Ntilde;", [NSNumber numberWithInteger:0x00d1],
180 @"&Ograve;", [NSNumber numberWithInteger:0x00d2],
181 @"&Oacute;", [NSNumber numberWithInteger:0x00d3],
182 @"&Ocirc;", [NSNumber numberWithInteger:0x00d4],
183 @"&Otilde;", [NSNumber numberWithInteger:0x00d5],
184 @"&Ouml;", [NSNumber numberWithInteger:0x00d6],
185 @"&times;", [NSNumber numberWithInteger:0x00d7],
186 @"&Oslash;", [NSNumber numberWithInteger:0x00d8],
187 @"&Ugrave;", [NSNumber numberWithInteger:0x00d9],
188 @"&Uacute;", [NSNumber numberWithInteger:0x00da],
189 @"&Ucirc;", [NSNumber numberWithInteger:0x00db],
190 @"&Uuml;", [NSNumber numberWithInteger:0x00dc],
191 @"&Yacute;", [NSNumber numberWithInteger:0x00dd],
192 @"&THORN;", [NSNumber numberWithInteger:0x00de],
193 @"&szlig;", [NSNumber numberWithInteger:0x00df],
194 @"&agrave;", [NSNumber numberWithInteger:0x00e0],
195 @"&aacute;", [NSNumber numberWithInteger:0x00e1],
196 @"&acirc;", [NSNumber numberWithInteger:0x00e2],
197 @"&atilde;", [NSNumber numberWithInteger:0x00e3],
198 @"&auml;", [NSNumber numberWithInteger:0x00e4],
199 @"&aring;", [NSNumber numberWithInteger:0x00e5],
200 @"&aelig;", [NSNumber numberWithInteger:0x00e6],
201 @"&ccedil;", [NSNumber numberWithInteger:0x00e7],
202 @"&egrave;", [NSNumber numberWithInteger:0x00e8],
203 @"&eacute;", [NSNumber numberWithInteger:0x00e9],
204 @"&ecirc;", [NSNumber numberWithInteger:0x00ea],
205 @"&euml;", [NSNumber numberWithInteger:0x00eb],
206 @"&igrave;", [NSNumber numberWithInteger:0x00ec],
207 @"&iacute;", [NSNumber numberWithInteger:0x00ed],
208 @"&icirc;", [NSNumber numberWithInteger:0x00ee],
209 @"&iuml;", [NSNumber numberWithInteger:0x00ef],
210 @"&eth;", [NSNumber numberWithInteger:0x00f0],
211 @"&ntilde;", [NSNumber numberWithInteger:0x00f1],
212 @"&ograve;", [NSNumber numberWithInteger:0x00f2],
213 @"&oacute;", [NSNumber numberWithInteger:0x00f3],
214 @"&ocirc;", [NSNumber numberWithInteger:0x00f4],
215 @"&otilde;", [NSNumber numberWithInteger:0x00f5],
216 @"&ouml;", [NSNumber numberWithInteger:0x00f6],
217 @"&divide;", [NSNumber numberWithInteger:0x00f7],
218 @"&oslash;", [NSNumber numberWithInteger:0x00f8],
219 @"&ugrave;", [NSNumber numberWithInteger:0x00f9],
220 @"&uacute;", [NSNumber numberWithInteger:0x00fa],
221 @"&ucirc;", [NSNumber numberWithInteger:0x00fb],
222 @"&uuml;", [NSNumber numberWithInteger:0x00fc],
223 @"&yacute;", [NSNumber numberWithInteger:0x00fd],
224 @"&thorn;", [NSNumber numberWithInteger:0x00fe],
225 @"&yuml;", [NSNumber numberWithInteger:0x00ff],
226 @"&OElig;", [NSNumber numberWithInteger:0x0152],
227 @"&oelig;", [NSNumber numberWithInteger:0x0153],
228 @"&Scaron;", [NSNumber numberWithInteger:0x0160],
229 @"&scaron;", [NSNumber numberWithInteger:0x0161],
230 @"&Yuml;", [NSNumber numberWithInteger:0x0178],
231 @"&fnof;", [NSNumber numberWithInteger:0x0192],
232 @"&circ;", [NSNumber numberWithInteger:0x02c6],
233 @"&tilde;", [NSNumber numberWithInteger:0x02dc],
234 @"&Gamma;", [NSNumber numberWithInteger:0x0393],
235 @"&Delta;", [NSNumber numberWithInteger:0x0394],
236 @"&Theta;", [NSNumber numberWithInteger:0x0398],
237 @"&Lambda;", [NSNumber numberWithInteger:0x039b],
238 @"&Xi;", [NSNumber numberWithInteger:0x039e],
239 @"&Sigma;", [NSNumber numberWithInteger:0x03a3],
240 @"&Upsilon;", [NSNumber numberWithInteger:0x03a5],
241 @"&Phi;", [NSNumber numberWithInteger:0x03a6],
242 @"&Psi;", [NSNumber numberWithInteger:0x03a8],
243 @"&Omega;", [NSNumber numberWithInteger:0x03a9],
244 @"&alpha;", [NSNumber numberWithInteger:0x03b1],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
245 @"&Alpha;", [NSNumber numberWithInteger:0x0391],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
246 @"&beta;", [NSNumber numberWithInteger:0x03b2],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
247 @"&Beta;", [NSNumber numberWithInteger:0x0392],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
248 @"&gamma;", [NSNumber numberWithInteger:0x03b3],
249 @"&delta;", [NSNumber numberWithInteger:0x03b4],
250 @"&epsilon;", [NSNumber numberWithInteger:0x03b5],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
251 @"&Epsilon;", [NSNumber numberWithInteger:0x0395],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
252 @"&zeta;", [NSNumber numberWithInteger:0x03b6],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
253 @"&Zeta;", [NSNumber numberWithInteger:0x0396],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
254 @"&eta;", [NSNumber numberWithInteger:0x03b7],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
255 @"&Eta;", [NSNumber numberWithInteger:0x0397],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
256 @"&theta;", [NSNumber numberWithInteger:0x03b8],
257 @"&iota;", [NSNumber numberWithInteger:0x03b9],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
258 @"&Iota;", [NSNumber numberWithInteger:0x0399],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
259 @"&kappa;", [NSNumber numberWithInteger:0x03ba],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
260 @"&Kappa;", [NSNumber numberWithInteger:0x039a],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
261 @"&lambda;", [NSNumber numberWithInteger:0x03bb],
262 @"&mu;", [NSNumber numberWithInteger:0x03bc],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
263 @"&Mu;", [NSNumber numberWithInteger:0x039c],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
264 @"&nu;", [NSNumber numberWithInteger:0x03bd],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
265 @"&Nu;", [NSNumber numberWithInteger:0x039d],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
266 @"&xi;", [NSNumber numberWithInteger:0x03be],
267 @"&omicron;", [NSNumber numberWithInteger:0x03bf],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
268 @"&Omicron;", [NSNumber numberWithInteger:0x039f],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
269 @"&pi;", [NSNumber numberWithInteger:0x03c0],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
270 @"&Pi;", [NSNumber numberWithInteger:0x03a0],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
271 @"&rho;", [NSNumber numberWithInteger:0x03c1],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
272 @"&Rho;", [NSNumber numberWithInteger:0x03a1],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
273 @"&sigmaf;", [NSNumber numberWithInteger:0x03c2],
274 @"&sigma;", [NSNumber numberWithInteger:0x03c3],
275 @"&tau;", [NSNumber numberWithInteger:0x03c4],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
276 @"&Tau;", [NSNumber numberWithInteger:0x03a4],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
277 @"&upsilon;", [NSNumber numberWithInteger:0x03c5],
278 @"&phi;", [NSNumber numberWithInteger:0x03c6],
279 @"&chi;", [NSNumber numberWithInteger:0x03c7],
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
280 @"&Chi;", [NSNumber numberWithInteger:0x03a7],
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
281 @"&psi;", [NSNumber numberWithInteger:0x03c8],
282 @"&omega;", [NSNumber numberWithInteger:0x03c9],
283 @"&thetasym;", [NSNumber numberWithInteger:0x03d1],
284 @"&upsih;", [NSNumber numberWithInteger:0x03d2],
285 @"&piv;", [NSNumber numberWithInteger:0x03d6],
286 @"&ensp;", [NSNumber numberWithInteger:0x2002],
287 @"&emsp;", [NSNumber numberWithInteger:0x2003],
288 @"&thinsp;", [NSNumber numberWithInteger:0x2009],
289 @"&ndash;", [NSNumber numberWithInteger:0x2013],
290 @"&mdash;", [NSNumber numberWithInteger:0x2014],
291 @"&lsquo;", [NSNumber numberWithInteger:0x2018],
292 @"&rsquo;", [NSNumber numberWithInteger:0x2019],
293 @"&sbquo;", [NSNumber numberWithInteger:0x201a],
294 @"&ldquo;", [NSNumber numberWithInteger:0x201c],
295 @"&rdquo;", [NSNumber numberWithInteger:0x201d],
296 @"&bdquo;", [NSNumber numberWithInteger:0x201e],
297 @"&dagger;", [NSNumber numberWithInteger:0x2020],
298 @"&Dagger;", [NSNumber numberWithInteger:0x2021],
299 @"&bull;", [NSNumber numberWithInteger:0x2022],
300 @"&hellip;", [NSNumber numberWithInteger:0x2026],
301 @"&permil;", [NSNumber numberWithInteger:0x2030],
302 @"&prime;", [NSNumber numberWithInteger:0x2032],
303 @"&Prime;", [NSNumber numberWithInteger:0x2033],
304 @"&lsaquo;", [NSNumber numberWithInteger:0x2039],
305 @"&rsaquo;", [NSNumber numberWithInteger:0x203a],
306 @"&oline;", [NSNumber numberWithInteger:0x203e],
307 @"&frasl;", [NSNumber numberWithInteger:0x2044],
308 @"&euro;", [NSNumber numberWithInteger:0x20ac],
309 @"&image;", [NSNumber numberWithInteger:0x2111],
310 @"&weierp;", [NSNumber numberWithInteger:0x2118],
311 @"&real;", [NSNumber numberWithInteger:0x211c],
312 @"&trade;", [NSNumber numberWithInteger:0x2122],
313 @"&alefsym;", [NSNumber numberWithInteger:0x2135],
314 @"&larr;", [NSNumber numberWithInteger:0x2190],
315 @"&uarr;", [NSNumber numberWithInteger:0x2191],
316 @"&rarr;", [NSNumber numberWithInteger:0x2192],
317 @"&darr;", [NSNumber numberWithInteger:0x2193],
318 @"&harr;", [NSNumber numberWithInteger:0x2194],
319 @"&crarr;", [NSNumber numberWithInteger:0x21b5],
320 @"&lArr;", [NSNumber numberWithInteger:0x21d0],
321 @"&uArr;", [NSNumber numberWithInteger:0x21d1],
322 @"&rArr;", [NSNumber numberWithInteger:0x21d2],
323 @"&dArr;", [NSNumber numberWithInteger:0x21d3],
324 @"&hArr;", [NSNumber numberWithInteger:0x21d4],
325 @"&forall;", [NSNumber numberWithInteger:0x2200],
326 @"&part;", [NSNumber numberWithInteger:0x2202],
327 @"&exist;", [NSNumber numberWithInteger:0x2203],
328 @"&empty;", [NSNumber numberWithInteger:0x2205],
329 @"&nabla;", [NSNumber numberWithInteger:0x2207],
330 @"&isin;", [NSNumber numberWithInteger:0x2208],
331 @"&notin;", [NSNumber numberWithInteger:0x2209],
332 @"&ni;", [NSNumber numberWithInteger:0x220b],
333 @"&prod;", [NSNumber numberWithInteger:0x220f],
334 @"&sum;", [NSNumber numberWithInteger:0x2211],
335 @"&minus;", [NSNumber numberWithInteger:0x2212],
336 @"&lowast;", [NSNumber numberWithInteger:0x2217],
337 @"&radic;", [NSNumber numberWithInteger:0x221a],
338 @"&prop;", [NSNumber numberWithInteger:0x221d],
339 @"&infin;", [NSNumber numberWithInteger:0x221e],
340 @"&ang;", [NSNumber numberWithInteger:0x2220],
341 @"&and;", [NSNumber numberWithInteger:0x2227],
342 @"&or;", [NSNumber numberWithInteger:0x2228],
343 @"&cap;", [NSNumber numberWithInteger:0x2229],
344 @"&cup;", [NSNumber numberWithInteger:0x222a],
345 @"&int;", [NSNumber numberWithInteger:0x222b],
346 @"&there4;", [NSNumber numberWithInteger:0x2234],
347 @"&sim;", [NSNumber numberWithInteger:0x223c],
348 @"&cong;", [NSNumber numberWithInteger:0x2245],
349 @"&asymp;", [NSNumber numberWithInteger:0x2248],
350 @"&ne;", [NSNumber numberWithInteger:0x2260],
351 @"&equiv;", [NSNumber numberWithInteger:0x2261],
352 @"&le;", [NSNumber numberWithInteger:0x2264],
353 @"&ge;", [NSNumber numberWithInteger:0x2265],
354 @"&sub;", [NSNumber numberWithInteger:0x2282],
355 @"&sup;", [NSNumber numberWithInteger:0x2283],
356 @"&nsub;", [NSNumber numberWithInteger:0x2284],
357 @"&sube;", [NSNumber numberWithInteger:0x2286],
358 @"&supe;", [NSNumber numberWithInteger:0x2287],
359 @"&oplus;", [NSNumber numberWithInteger:0x2295],
360 @"&otimes;", [NSNumber numberWithInteger:0x2297],
361 @"&perp;", [NSNumber numberWithInteger:0x22a5],
362 @"&sdot;", [NSNumber numberWithInteger:0x22c5],
363 @"&lceil;", [NSNumber numberWithInteger:0x2308],
364 @"&rceil;", [NSNumber numberWithInteger:0x2309],
365 @"&lfloor;", [NSNumber numberWithInteger:0x230a],
366 @"&rfloor;", [NSNumber numberWithInteger:0x230b],
367 @"&lang;", [NSNumber numberWithInteger:0x27e8],
368 @"&rang;", [NSNumber numberWithInteger:0x27e9],
369 @"&loz;", [NSNumber numberWithInteger:0x25ca],
370 @"&spades;", [NSNumber numberWithInteger:0x2660],
371 @"&clubs;", [NSNumber numberWithInteger:0x2663],
372 @"&hearts;", [NSNumber numberWithInteger:0x2665],
373 @"&diams;", [NSNumber numberWithInteger:0x2666],
374 @"<br />", [NSNumber numberWithInteger:0x2028],
375 nil];
376
7f42dff2 »
2011-09-14 Fixed crash on 3.2, removed duplicate lines of code
377 });
64101f15 »
2011-08-28 Added HTML entity encoding for strings, improved output of text attac…
378
379 NSMutableString *tmpString = [NSMutableString string];
380
06980a28 » dhoerl18
2011-12-02 Debug a retain cycle; moved ivars to implementation; cleared all warn…
381 for (NSUInteger i = 0; i<[self length]; i++)
64101f15 »
2011-08-28 Added HTML entity encoding for strings, improved output of text attac…
382 {
383 unichar oneChar = [self characterAtIndex:i];
384
385 NSNumber *subKey = [NSNumber numberWithInteger:oneChar];
386 NSString *entity = [entityReverseLookup objectForKey:subKey];
387
388 if (entity)
389 {
390 [tmpString appendString:entity];
391 }
392 else
393 {
394 if (oneChar<=255)
395 {
396 [tmpString appendFormat:@"%C", oneChar];
397 }
398 else
399 {
400 [tmpString appendFormat:@"&#%d;", oneChar];
401 }
402 }
403 }
404
405 return tmpString;
406 }
407
b9c51761 »
2011-01-18 Added HTML entity decoding
408 - (NSString *)stringByReplacingHTMLEntities
409 {
e5e15680 » johnezang
2011-06-27 Add multi-threading safe initialization of singleton objects. Off by …
410 static dispatch_once_t predicate;
c967589a » dhoerl
2011-11-21 Fixed up project so it would build (removed dependencies on DTWebArch…
411 dispatch_once(&predicate, ^{
689966fb »
2011-01-31 Added support from CSS style text-shadow
412 entityLookup = [[NSDictionary alloc] initWithObjectsAndKeys:@"\x22", @"quot",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
413 @"\x26", @"amp",
414 @"\x27", @"apos",
415 @"\x3c", @"lt",
416 @"\x3e", @"gt",
417 @"\u00a0", @"nbsp",
418 @"\u00a1", @"iexcl",
419 @"\u00a2", @"cent",
420 @"\u00a3", @"pound",
421 @"\u00a4", @"curren",
422 @"\u00a5", @"yen",
423 @"\u00a6", @"brvbar",
424 @"\u00a7", @"sect",
425 @"\u00a8", @"uml",
426 @"\u00a9", @"copy",
427 @"\u00aa", @"ordf",
428 @"\u00ab", @"laquo",
429 @"\u00ac", @"not",
430 @"\u00ae", @"reg",
431 @"\u00af", @"macr",
432 @"\u00b0", @"deg",
433 @"\u00b1", @"plusmn",
434 @"\u00b2", @"sup2",
435 @"\u00b3", @"sup3",
436 @"\u00b4", @"acute",
437 @"\u00b5", @"micro",
438 @"\u00b6", @"para",
439 @"\u00b7", @"middot",
440 @"\u00b8", @"cedil",
441 @"\u00b9", @"sup1",
442 @"\u00ba", @"ordm",
443 @"\u00bb", @"raquo",
444 @"\u00bc", @"frac14",
445 @"\u00bd", @"frac12",
446 @"\u00be", @"frac34",
447 @"\u00bf", @"iquest",
448 @"\u00c0", @"Agrave",
449 @"\u00c1", @"Aacute",
450 @"\u00c2", @"Acirc",
451 @"\u00c3", @"Atilde",
452 @"\u00c4", @"Auml",
453 @"\u00c5", @"Aring",
454 @"\u00c6", @"AElig",
455 @"\u00c7", @"Ccedil",
456 @"\u00c8", @"Egrave",
457 @"\u00c9", @"Eacute",
458 @"\u00ca", @"Ecirc",
459 @"\u00cb", @"Euml",
460 @"\u00cc", @"Igrave",
461 @"\u00cd", @"Iacute",
462 @"\u00ce", @"Icirc",
463 @"\u00cf", @"Iuml",
464 @"\u00d0", @"ETH",
465 @"\u00d1", @"Ntilde",
466 @"\u00d2", @"Ograve",
467 @"\u00d3", @"Oacute",
468 @"\u00d4", @"Ocirc",
469 @"\u00d5", @"Otilde",
470 @"\u00d6", @"Ouml",
471 @"\u00d7", @"times",
472 @"\u00d8", @"Oslash",
473 @"\u00d9", @"Ugrave",
474 @"\u00da", @"Uacute",
475 @"\u00db", @"Ucirc",
476 @"\u00dc", @"Uuml",
477 @"\u00dd", @"Yacute",
478 @"\u00de", @"THORN",
479 @"\u00df", @"szlig",
480 @"\u00e0", @"agrave",
481 @"\u00e1", @"aacute",
482 @"\u00e2", @"acirc",
483 @"\u00e3", @"atilde",
484 @"\u00e4", @"auml",
485 @"\u00e5", @"aring",
486 @"\u00e6", @"aelig",
487 @"\u00e7", @"ccedil",
488 @"\u00e8", @"egrave",
489 @"\u00e9", @"eacute",
490 @"\u00ea", @"ecirc",
491 @"\u00eb", @"euml",
492 @"\u00ec", @"igrave",
493 @"\u00ed", @"iacute",
494 @"\u00ee", @"icirc",
495 @"\u00ef", @"iuml",
496 @"\u00f0", @"eth",
497 @"\u00f1", @"ntilde",
498 @"\u00f2", @"ograve",
499 @"\u00f3", @"oacute",
500 @"\u00f4", @"ocirc",
501 @"\u00f5", @"otilde",
502 @"\u00f6", @"ouml",
503 @"\u00f7", @"divide",
504 @"\u00f8", @"oslash",
505 @"\u00f9", @"ugrave",
506 @"\u00fa", @"uacute",
507 @"\u00fb", @"ucirc",
508 @"\u00fc", @"uuml",
509 @"\u00fd", @"yacute",
510 @"\u00fe", @"thorn",
511 @"\u00ff", @"yuml",
512 @"\u0152", @"OElig",
513 @"\u0153", @"oelig",
514 @"\u0160", @"Scaron",
515 @"\u0161", @"scaron",
516 @"\u0178", @"Yuml",
517 @"\u0192", @"fnof",
518 @"\u02c6", @"circ",
519 @"\u02dc", @"tilde",
520 @"\u0393", @"Gamma",
521 @"\u0394", @"Delta",
522 @"\u0398", @"Theta",
523 @"\u039b", @"Lambda",
524 @"\u039e", @"Xi",
525 @"\u03a3", @"Sigma",
526 @"\u03a5", @"Upsilon",
527 @"\u03a6", @"Phi",
528 @"\u03a8", @"Psi",
529 @"\u03a9", @"Omega",
530 @"\u03b1", @"alpha",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
531 @"\u0391", @"Alpha",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
532 @"\u03b2", @"beta",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
533 @"\u0392", @"Beta",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
534 @"\u03b3", @"gamma",
535 @"\u03b4", @"delta",
536 @"\u03b5", @"epsilon",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
537 @"\u0395", @"Epsilon",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
538 @"\u03b6", @"zeta",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
539 @"\u0396", @"Zeta",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
540 @"\u03b7", @"eta",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
541 @"\u0397", @"Eta",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
542 @"\u03b8", @"theta",
543 @"\u03b9", @"iota",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
544 @"\u0399", @"Iota",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
545 @"\u03ba", @"kappa",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
546 @"\u039a", @"Kappa",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
547 @"\u03bb", @"lambda",
548 @"\u03bc", @"mu",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
549 @"\u039c", @"Mu",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
550 @"\u03bd", @"nu",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
551 @"\u039d", @"Nu",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
552 @"\u03be", @"xi",
553 @"\u03bf", @"omicron",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
554 @"\u039f", @"Omicron",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
555 @"\u03c0", @"pi",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
556 @"\u03a0", @"Pi",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
557 @"\u03c1", @"rho",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
558 @"\u03a1", @"Rho",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
559 @"\u03c2", @"sigmaf",
560 @"\u03c3", @"sigma",
561 @"\u03c4", @"tau",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
562 @"\u03a4", @"Tau",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
563 @"\u03c5", @"upsilon",
564 @"\u03c6", @"phi",
565 @"\u03c7", @"chi",
05cd54db » sebreh
2012-01-31 Added missing greek HTML entities
566 @"\u03a7", @"Chi",
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
567 @"\u03c8", @"psi",
568 @"\u03c9", @"omega",
569 @"\u03d1", @"thetasym",
570 @"\u03d2", @"upsih",
571 @"\u03d6", @"piv",
572 @"\u2002", @"ensp",
573 @"\u2003", @"emsp",
574 @"\u2009", @"thinsp",
575 @"\u2013", @"ndash",
576 @"\u2014", @"mdash",
577 @"\u2018", @"lsquo",
578 @"\u2019", @"rsquo",
579 @"\u201a", @"sbquo",
580 @"\u201c", @"ldquo",
581 @"\u201d", @"rdquo",
582 @"\u201e", @"bdquo",
583 @"\u2020", @"dagger",
584 @"\u2021", @"Dagger",
585 @"\u2022", @"bull",
586 @"\u2026", @"hellip",
587 @"\u2030", @"permil",
588 @"\u2032", @"prime",
589 @"\u2033", @"Prime",
590 @"\u2039", @"lsaquo",
591 @"\u203a", @"rsaquo",
592 @"\u203e", @"oline",
593 @"\u2044", @"frasl",
594 @"\u20ac", @"euro",
595 @"\u2111", @"image",
596 @"\u2118", @"weierp",
597 @"\u211c", @"real",
598 @"\u2122", @"trade",
599 @"\u2135", @"alefsym",
600 @"\u2190", @"larr",
601 @"\u2191", @"uarr",
602 @"\u2192", @"rarr",
603 @"\u2193", @"darr",
604 @"\u2194", @"harr",
605 @"\u21b5", @"crarr",
606 @"\u21d0", @"lArr",
607 @"\u21d1", @"uArr",
608 @"\u21d2", @"rArr",
609 @"\u21d3", @"dArr",
610 @"\u21d4", @"hArr",
611 @"\u2200", @"forall",
612 @"\u2202", @"part",
613 @"\u2203", @"exist",
614 @"\u2205", @"empty",
615 @"\u2207", @"nabla",
616 @"\u2208", @"isin",
617 @"\u2209", @"notin",
618 @"\u220b", @"ni",
619 @"\u220f", @"prod",
620 @"\u2211", @"sum",
621 @"\u2212", @"minus",
622 @"\u2217", @"lowast",
623 @"\u221a", @"radic",
624 @"\u221d", @"prop",
625 @"\u221e", @"infin",
626 @"\u2220", @"ang",
627 @"\u2227", @"and",
628 @"\u2228", @"or",
629 @"\u2229", @"cap",
630 @"\u222a", @"cup",
631 @"\u222b", @"int",
632 @"\u2234", @"there4",
633 @"\u223c", @"sim",
634 @"\u2245", @"cong",
635 @"\u2248", @"asymp",
636 @"\u2260", @"ne",
637 @"\u2261", @"equiv",
638 @"\u2264", @"le",
639 @"\u2265", @"ge",
640 @"\u2282", @"sub",
641 @"\u2283", @"sup",
642 @"\u2284", @"nsub",
643 @"\u2286", @"sube",
644 @"\u2287", @"supe",
645 @"\u2295", @"oplus",
646 @"\u2297", @"otimes",
647 @"\u22a5", @"perp",
648 @"\u22c5", @"sdot",
649 @"\u2308", @"lceil",
650 @"\u2309", @"rceil",
651 @"\u230a", @"lfloor",
652 @"\u230b", @"rfloor",
653 @"\u27e8", @"lang",
654 @"\u27e9", @"rang",
655 @"\u25ca", @"loz",
656 @"\u2660", @"spades",
657 @"\u2663", @"clubs",
658 @"\u2665", @"hearts",
659 @"\u2666", @"diams",
660 nil];
7f42dff2 »
2011-09-14 Fixed crash on 3.2, removed duplicate lines of code
661
662 });
f4f2f32d »
2012-01-29 rewrote pixelSizeOfCSSMeasureRelativeToCurrentTextSize for 5% speed gain
663
689966fb »
2011-01-31 Added support from CSS style text-shadow
664 NSScanner *scanner = [NSScanner scannerWithString:self];
665 [scanner setCharactersToBeSkipped:nil];
666
667 NSMutableString *output = [NSMutableString string];
668
669
670 while (![scanner isAtEnd])
671 {
672 NSString *scanned = nil;
673
674 if ([scanner scanUpToString:@"&" intoString:&scanned])
675 {
676 [output appendString:scanned];
677 }
678
679 if ([scanner scanString:@"&" intoString:NULL])
680 {
681 NSString *afterAmpersand = nil;
5dca397c »
2011-03-15 Removed trailing ;, modified DTCoreTextLayouter to give me layout fra…
682 if ([scanner scanUpToString:@";" intoString:&afterAmpersand])
689966fb »
2011-01-31 Added support from CSS style text-shadow
683 {
684 if ([scanner scanString:@";" intoString:NULL])
685 {
f91aa815 »
2012-01-24 fixed possibility of higher value for ampersand-encoding
686 if ([afterAmpersand hasPrefix:@"#"] && [afterAmpersand length]<=6)
689966fb »
2011-01-31 Added support from CSS style text-shadow
687 {
7c5133d6 »
2012-03-21 fixed two format specifier compiler warnings. #147
688 unichar ch = (unichar)[[afterAmpersand substringFromIndex:1] integerValue];
689 [output appendFormat:@"%C", ch];
689966fb »
2011-01-31 Added support from CSS style text-shadow
690 }
691 else
692 {
693 NSString *converted = [entityLookup objectForKey:afterAmpersand];
694
695 if (converted)
696 {
697 [output appendString:converted];
698 }
699 else
700 {
701 // not a valid sequence
702 [output appendString:@"&"];
703 [output appendString:afterAmpersand];
704 [output appendString:@";"];
705 }
706 }
707
708 }
709 else
710 {
711 // no semicolon
712 [output appendString:@"&"];
713 [output appendString:afterAmpersand];
714 }
715 }
716 }
717 }
718
719
720 return [NSString stringWithString:output];
b9c51761 »
2011-01-18 Added HTML entity decoding
721 }
722
4a36b77f »
2011-03-24 Strict warnings and Xcode cleanup
723 #pragma mark Utility
eec6191f »
2011-03-21 Link parts of A tag via GUID so that all highlight at the same time
724 + (NSString *)guid
725 {
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
726 CFUUIDRef uuid = CFUUIDCreate(NULL);
727 CFStringRef cfStr = CFUUIDCreateString(NULL, uuid);
728
05aa188e » dhoerl
2011-12-02 Looking real good now - no leaks
729 NSString *ret = [NSString stringWithString:CFBridgingRelease(cfStr)];
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
730
731 CFRelease(uuid);
05aa188e » dhoerl
2011-12-02 Looking real good now - no leaks
732 // CFRelease(cfStr);
7528d115 » jonsterling
2011-06-25 Normalized indentation (tabs)
733
734 return ret;
eec6191f »
2011-03-21 Link parts of A tag via GUID so that all highlight at the same time
735 }
736
cb449bb9 »
2011-01-10 Added Project Files
737 @end
Something went wrong with that request. Please try again.