]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmlpars.cpp
applied patch 446836: removed qt headers
[wxWidgets.git] / src / html / htmlpars.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlpars.cpp
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "wx/wxprec.h"
16
17 #include "wx/defs.h"
18 #if wxUSE_HTML && wxUSE_STREAMS
19
20 #ifdef __BORDLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WXPRECOMP
25 #include "wx/log.h"
26 #include "wx/intl.h"
27 #endif
28
29 #include "wx/tokenzr.h"
30 #include "wx/wfstream.h"
31 #include "wx/url.h"
32 #include "wx/fontmap.h"
33 #include "wx/html/htmldefs.h"
34 #include "wx/html/htmlpars.h"
35 #include "wx/dynarray.h"
36 #include "wx/arrimpl.cpp"
37
38 //-----------------------------------------------------------------------------
39 // wxHtmlParser helpers
40 //-----------------------------------------------------------------------------
41
42 class wxHtmlTextPiece
43 {
44 public:
45 wxHtmlTextPiece(int pos, int lng) : m_pos(pos), m_lng(lng) {}
46 int m_pos, m_lng;
47 };
48
49 WX_DECLARE_OBJARRAY(wxHtmlTextPiece, wxHtmlTextPieces);
50 WX_DEFINE_OBJARRAY(wxHtmlTextPieces);
51
52 class wxHtmlParserState
53 {
54 public:
55 wxHtmlTag *m_curTag;
56 wxHtmlTag *m_tags;
57 wxHtmlTextPieces *m_textPieces;
58 int m_curTextPiece;
59 wxString m_source;
60 wxHtmlParserState *m_nextState;
61 };
62
63 //-----------------------------------------------------------------------------
64 // wxHtmlParser
65 //-----------------------------------------------------------------------------
66
67 IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
68
69 wxHtmlParser::wxHtmlParser()
70 : wxObject(), m_HandlersHash(wxKEY_STRING),
71 m_FS(NULL), m_HandlersStack(NULL)
72 {
73 m_entitiesParser = new wxHtmlEntitiesParser;
74 m_Tags = NULL;
75 m_CurTag = NULL;
76 m_TextPieces = NULL;
77 m_CurTextPiece = 0;
78 m_SavedStates = NULL;
79 }
80
81 wxHtmlParser::~wxHtmlParser()
82 {
83 while (RestoreState())
84 DestroyDOMTree();
85 delete m_HandlersStack;
86 m_HandlersHash.Clear();
87 m_HandlersList.DeleteContents(TRUE);
88 m_HandlersList.Clear();
89 delete m_entitiesParser;
90 }
91
92 wxObject* wxHtmlParser::Parse(const wxString& source)
93 {
94 wxObject *result;
95
96 InitParser(source);
97 DoParsing();
98 result = GetProduct();
99 DoneParser();
100 return result;
101 }
102
103 void wxHtmlParser::InitParser(const wxString& source)
104 {
105 SetSource(source);
106 }
107
108 void wxHtmlParser::DoneParser()
109 {
110 DestroyDOMTree();
111 }
112
113 void wxHtmlParser::SetSource(const wxString& src)
114 {
115 DestroyDOMTree();
116 m_Source = src;
117 CreateDOMTree();
118 m_CurTag = NULL;
119 m_CurTextPiece = 0;
120 }
121
122 void wxHtmlParser::CreateDOMTree()
123 {
124 wxHtmlTagsCache cache(m_Source);
125 m_TextPieces = new wxHtmlTextPieces;
126 CreateDOMSubTree(NULL, 0, m_Source.Length(), &cache);
127 m_CurTextPiece = 0;
128 }
129
130 void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur,
131 int begin_pos, int end_pos,
132 wxHtmlTagsCache *cache)
133 {
134 if (end_pos <= begin_pos) return;
135
136 wxChar c;
137 int i = begin_pos;
138 int textBeginning = begin_pos;
139
140 while (i < end_pos)
141 {
142 c = m_Source.GetChar(i);
143
144 if (c == wxT('<'))
145 {
146 // add text to m_TextPieces:
147 if (i - textBeginning > 0)
148 m_TextPieces->Add(
149 wxHtmlTextPiece(textBeginning, i - textBeginning));
150
151 // if it is a comment, skip it:
152 if (i < end_pos-6 && m_Source.GetChar(i+1) == wxT('!') &&
153 m_Source.GetChar(i+2) == wxT('-') &&
154 m_Source.GetChar(i+3) == wxT('-'))
155 {
156 // Comments begin with "<!--" and end with "--[ \t\r\n]*>"
157 // according to HTML 4.0
158 int dashes = 0;
159 i += 4;
160 while (i < end_pos)
161 {
162 c = m_Source.GetChar(i++);
163 if ((c == wxT(' ') || c == wxT('\n') ||
164 c == wxT('\r') || c == wxT('\t')) && dashes >= 2) {}
165 else if (c == wxT('>') && dashes >= 2)
166 {
167 textBeginning = i;
168 break;
169 }
170 else if (c == wxT('-'))
171 dashes++;
172 else
173 dashes = 0;
174 }
175 }
176
177 // add another tag to the tree:
178 else if (i < end_pos-1 && m_Source.GetChar(i+1) != wxT('/'))
179 {
180 wxHtmlTag *chd;
181 if (cur)
182 chd = new wxHtmlTag(cur, m_Source,
183 i, end_pos, cache, m_entitiesParser);
184 else
185 {
186 chd = new wxHtmlTag(NULL, m_Source,
187 i, end_pos, cache, m_entitiesParser);
188 if (!m_Tags)
189 {
190 // if this is the first tag to be created make the root
191 // m_Tags point to it:
192 m_Tags = chd;
193 }
194 else
195 {
196 // if there is already a root tag add this tag as
197 // the last sibling:
198 chd->m_Prev = m_Tags->GetLastSibling();
199 chd->m_Prev->m_Next = chd;
200 }
201 }
202
203 if (chd->HasEnding())
204 {
205 CreateDOMSubTree(chd,
206 chd->GetBeginPos(), chd->GetEndPos1(),
207 cache);
208 i = chd->GetEndPos2();
209 }
210 else
211 i = chd->GetBeginPos();
212 textBeginning = i;
213 }
214
215 // ... or skip ending tag:
216 else
217 {
218 while (i < end_pos && m_Source.GetChar(i) != wxT('>')) i++;
219 textBeginning = i+1;
220 }
221 }
222 else i++;
223 }
224
225 // add remaining text to m_TextPieces:
226 if (end_pos - textBeginning > 0)
227 m_TextPieces->Add(
228 wxHtmlTextPiece(textBeginning, end_pos - textBeginning));
229 }
230
231 void wxHtmlParser::DestroyDOMTree()
232 {
233 wxHtmlTag *t1, *t2;
234 t1 = m_Tags;
235 while (t1)
236 {
237 t2 = t1->GetNextSibling();
238 delete t1;
239 t1 = t2;
240 }
241 m_Tags = m_CurTag = NULL;
242
243 delete m_TextPieces;
244 m_TextPieces = NULL;
245 }
246
247 void wxHtmlParser::DoParsing()
248 {
249 m_CurTag = m_Tags;
250 m_CurTextPiece = 0;
251 DoParsing(0, m_Source.Length());
252 }
253
254 void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
255 {
256 if (end_pos <= begin_pos) return;
257
258 wxHtmlTextPieces& pieces = *m_TextPieces;
259 size_t piecesCnt = pieces.GetCount();
260
261 while (begin_pos < end_pos)
262 {
263 while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
264 m_CurTag = m_CurTag->GetNextTag();
265 while (m_CurTextPiece < piecesCnt &&
266 pieces[m_CurTextPiece].m_pos < begin_pos)
267 m_CurTextPiece++;
268
269 if (m_CurTextPiece < piecesCnt &&
270 (!m_CurTag ||
271 pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
272 {
273 // Add text:
274 AddText(GetEntitiesParser()->Parse(
275 m_Source.Mid(pieces[m_CurTextPiece].m_pos,
276 pieces[m_CurTextPiece].m_lng)));
277 begin_pos = pieces[m_CurTextPiece].m_pos +
278 pieces[m_CurTextPiece].m_lng;
279 m_CurTextPiece++;
280 }
281 else if (m_CurTag)
282 {
283 // Add tag:
284 if (m_CurTag)
285 {
286 if (m_CurTag->HasEnding())
287 begin_pos = m_CurTag->GetEndPos2();
288 else
289 begin_pos = m_CurTag->GetBeginPos();
290 }
291 wxHtmlTag *t = m_CurTag;
292 m_CurTag = m_CurTag->GetNextTag();
293 AddTag(*t);
294 }
295 else break;
296 }
297 }
298
299 void wxHtmlParser::AddTag(const wxHtmlTag& tag)
300 {
301 wxHtmlTagHandler *h;
302 bool inner = FALSE;
303
304 h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName());
305 if (h)
306 inner = h->HandleTag(tag);
307 if (!inner)
308 {
309 if (tag.HasEnding())
310 DoParsing(tag.GetBeginPos(), tag.GetEndPos1());
311 }
312 }
313
314 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
315 {
316 wxString s(handler->GetSupportedTags());
317 wxStringTokenizer tokenizer(s, wxT(", "));
318
319 while (tokenizer.HasMoreTokens())
320 m_HandlersHash.Put(tokenizer.NextToken(), handler);
321
322 if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
323 m_HandlersList.Append(handler);
324
325 handler->SetParser(this);
326 }
327
328 void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags)
329 {
330 wxStringTokenizer tokenizer(tags, wxT(", "));
331 wxString key;
332
333 if (m_HandlersStack == NULL)
334 {
335 m_HandlersStack = new wxList;
336 m_HandlersStack->DeleteContents(TRUE);
337 }
338
339 m_HandlersStack->Insert(new wxHashTable(m_HandlersHash));
340
341 while (tokenizer.HasMoreTokens())
342 {
343 key = tokenizer.NextToken();
344 m_HandlersHash.Delete(key);
345 m_HandlersHash.Put(key, handler);
346 }
347 }
348
349 void wxHtmlParser::PopTagHandler()
350 {
351 wxNode *first;
352
353 if (m_HandlersStack == NULL ||
354 (first = m_HandlersStack->GetFirst()) == NULL)
355 {
356 wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
357 return;
358 }
359 m_HandlersHash = *((wxHashTable*) first->GetData());
360 m_HandlersStack->DeleteNode(first);
361 }
362
363 void wxHtmlParser::SetSourceAndSaveState(const wxString& src)
364 {
365 wxHtmlParserState *s = new wxHtmlParserState;
366
367 s->m_curTag = m_CurTag;
368 s->m_tags = m_Tags;
369 s->m_textPieces = m_TextPieces;
370 s->m_curTextPiece = m_CurTextPiece;
371 s->m_source = m_Source;
372
373 s->m_nextState = m_SavedStates;
374 m_SavedStates = s;
375
376 m_CurTag = NULL;
377 m_Tags = NULL;
378 m_TextPieces = NULL;
379 m_CurTextPiece = 0;
380 m_Source = wxEmptyString;
381
382 SetSource(src);
383 }
384
385 bool wxHtmlParser::RestoreState()
386 {
387 if (!m_SavedStates) return FALSE;
388
389 wxHtmlParserState *s = m_SavedStates;
390 m_SavedStates = s->m_nextState;
391
392 m_CurTag = s->m_curTag;
393 m_Tags = s->m_tags;
394 m_TextPieces = s->m_textPieces;
395 m_CurTextPiece = s->m_curTextPiece;
396 m_Source = s->m_source;
397
398 delete s;
399 return TRUE;
400 }
401
402 //-----------------------------------------------------------------------------
403 // wxHtmlTagHandler
404 //-----------------------------------------------------------------------------
405
406 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler,wxObject)
407
408
409 //-----------------------------------------------------------------------------
410 // wxHtmlEntitiesParser
411 //-----------------------------------------------------------------------------
412
413 IMPLEMENT_DYNAMIC_CLASS(wxHtmlEntitiesParser,wxObject)
414
415 wxHtmlEntitiesParser::wxHtmlEntitiesParser()
416 #if wxUSE_WCHAR_T && !wxUSE_UNICODE
417 : m_conv(NULL), m_encoding(wxFONTENCODING_SYSTEM)
418 #endif
419 {
420 }
421
422 wxHtmlEntitiesParser::~wxHtmlEntitiesParser()
423 {
424 #if wxUSE_WCHAR_T && !wxUSE_UNICODE
425 delete m_conv;
426 #endif
427 }
428
429 void wxHtmlEntitiesParser::SetEncoding(wxFontEncoding encoding)
430 {
431 #if wxUSE_WCHAR_T && !wxUSE_UNICODE
432 if (encoding == m_encoding) return;
433 delete m_conv;
434 m_conv = NULL;
435 m_encoding = encoding;
436 if (m_encoding != wxFONTENCODING_SYSTEM)
437 m_conv = new wxCSConv(wxFontMapper::GetEncodingName(m_encoding));
438 #else
439 (void) encoding;
440 #endif
441 }
442
443 wxString wxHtmlEntitiesParser::Parse(const wxString& input)
444 {
445 const wxChar *c, *last;
446 const wxChar *in_str = input.c_str();
447 wxString output;
448
449 for (c = in_str, last = in_str; *c != wxT('\0'); c++)
450 {
451 if (*c == wxT('&'))
452 {
453 if (c - last > 0)
454 output.append(last, c - last);
455 if (++c == wxT('\0')) break;
456 wxString entity;
457 const wxChar *ent_s = c;
458 for (; (*c >= wxT('a') && *c <= wxT('z')) ||
459 (*c >= wxT('A') && *c <= wxT('Z')) ||
460 (*c >= wxT('0') && *c <= wxT('9')) ||
461 *c == wxT('_') || *c == wxT('#'); c++) {}
462 entity.append(ent_s, c - ent_s);
463 if (*c != wxT(';')) c--;
464 last = c+1;
465 output << GetEntityChar(entity);
466 }
467 }
468 if (*last != wxT('\0'))
469 output.append(last);
470 return output;
471 }
472
473 struct wxHtmlEntityInfo
474 {
475 const wxChar *name;
476 unsigned code;
477 };
478
479 static int LINKAGEMODE compar_entity(const void *key, const void *item)
480 {
481 return wxStrcmp((wxChar*)key, ((wxHtmlEntityInfo*)item)->name);
482 }
483
484 wxChar wxHtmlEntitiesParser::GetCharForCode(unsigned code)
485 {
486 #if wxUSE_UNICODE
487 return (wxChar)code;
488 #elif wxUSE_WCHAR_T
489 char buf[2];
490 wchar_t wbuf[2];
491 wbuf[0] = (wchar_t)code;
492 wbuf[1] = 0;
493 wxMBConv *conv = m_conv ? m_conv : &wxConvLocal;
494 if (conv->WC2MB(buf, wbuf, 2) == (size_t)-1)
495 return '?';
496 return buf[0];
497 #else
498 return (code < 256) ? (wxChar)code : '?';
499 #endif
500 }
501
502 wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity)
503 {
504 unsigned code = 0;
505
506 if (entity[0] == wxT('#'))
507 {
508 const wxChar *ent_s = entity.c_str();
509 const wxChar *format;
510
511 if (ent_s[1] == wxT('x') || ent_s[1] == wxT('X'))
512 {
513 format = wxT("%x");
514 ent_s++;
515 }
516 else
517 format = wxT("%u");
518 ent_s++;
519
520 if (wxSscanf(ent_s, format, &code) != 1)
521 code = 0;
522 }
523 else
524 {
525 static wxHtmlEntityInfo substitutions[] = {
526 { wxT("AElig"),198 },
527 { wxT("Aacute"),193 },
528 { wxT("Acirc"),194 },
529 { wxT("Agrave"),192 },
530 { wxT("Alpha"),913 },
531 { wxT("Aring"),197 },
532 { wxT("Atilde"),195 },
533 { wxT("Auml"),196 },
534 { wxT("Beta"),914 },
535 { wxT("Ccedil"),199 },
536 { wxT("Chi"),935 },
537 { wxT("Dagger"),8225 },
538 { wxT("Delta"),916 },
539 { wxT("ETH"),208 },
540 { wxT("Eacute"),201 },
541 { wxT("Ecirc"),202 },
542 { wxT("Egrave"),200 },
543 { wxT("Epsilon"),917 },
544 { wxT("Eta"),919 },
545 { wxT("Euml"),203 },
546 { wxT("Gamma"),915 },
547 { wxT("Iacute"),205 },
548 { wxT("Icirc"),206 },
549 { wxT("Igrave"),204 },
550 { wxT("Iota"),921 },
551 { wxT("Iuml"),207 },
552 { wxT("Kappa"),922 },
553 { wxT("Lambda"),923 },
554 { wxT("Mu"),924 },
555 { wxT("Ntilde"),209 },
556 { wxT("Nu"),925 },
557 { wxT("OElig"),338 },
558 { wxT("Oacute"),211 },
559 { wxT("Ocirc"),212 },
560 { wxT("Ograve"),210 },
561 { wxT("Omega"),937 },
562 { wxT("Omicron"),927 },
563 { wxT("Oslash"),216 },
564 { wxT("Otilde"),213 },
565 { wxT("Ouml"),214 },
566 { wxT("Phi"),934 },
567 { wxT("Pi"),928 },
568 { wxT("Prime"),8243 },
569 { wxT("Psi"),936 },
570 { wxT("Rho"),929 },
571 { wxT("Scaron"),352 },
572 { wxT("Sigma"),931 },
573 { wxT("THORN"),222 },
574 { wxT("Tau"),932 },
575 { wxT("Theta"),920 },
576 { wxT("Uacute"),218 },
577 { wxT("Ucirc"),219 },
578 { wxT("Ugrave"),217 },
579 { wxT("Upsilon"),933 },
580 { wxT("Uuml"),220 },
581 { wxT("Xi"),926 },
582 { wxT("Yacute"),221 },
583 { wxT("Yuml"),376 },
584 { wxT("Zeta"),918 },
585 { wxT("aacute"),225 },
586 { wxT("acirc"),226 },
587 { wxT("acute"),180 },
588 { wxT("aelig"),230 },
589 { wxT("agrave"),224 },
590 { wxT("alefsym"),8501 },
591 { wxT("alpha"),945 },
592 { wxT("amp"),38 },
593 { wxT("and"),8743 },
594 { wxT("ang"),8736 },
595 { wxT("aring"),229 },
596 { wxT("asymp"),8776 },
597 { wxT("atilde"),227 },
598 { wxT("auml"),228 },
599 { wxT("bdquo"),8222 },
600 { wxT("beta"),946 },
601 { wxT("brvbar"),166 },
602 { wxT("bull"),8226 },
603 { wxT("cap"),8745 },
604 { wxT("ccedil"),231 },
605 { wxT("cedil"),184 },
606 { wxT("cent"),162 },
607 { wxT("chi"),967 },
608 { wxT("circ"),710 },
609 { wxT("clubs"),9827 },
610 { wxT("cong"),8773 },
611 { wxT("copy"),169 },
612 { wxT("crarr"),8629 },
613 { wxT("cup"),8746 },
614 { wxT("curren"),164 },
615 { wxT("dArr"),8659 },
616 { wxT("dagger"),8224 },
617 { wxT("darr"),8595 },
618 { wxT("deg"),176 },
619 { wxT("delta"),948 },
620 { wxT("diams"),9830 },
621 { wxT("divide"),247 },
622 { wxT("eacute"),233 },
623 { wxT("ecirc"),234 },
624 { wxT("egrave"),232 },
625 { wxT("empty"),8709 },
626 { wxT("emsp"),8195 },
627 { wxT("ensp"),8194 },
628 { wxT("epsilon"),949 },
629 { wxT("equiv"),8801 },
630 { wxT("eta"),951 },
631 { wxT("eth"),240 },
632 { wxT("euml"),235 },
633 { wxT("euro"),8364 },
634 { wxT("exist"),8707 },
635 { wxT("fnof"),402 },
636 { wxT("forall"),8704 },
637 { wxT("frac12"),189 },
638 { wxT("frac14"),188 },
639 { wxT("frac34"),190 },
640 { wxT("frasl"),8260 },
641 { wxT("gamma"),947 },
642 { wxT("ge"),8805 },
643 { wxT("gt"),62 },
644 { wxT("hArr"),8660 },
645 { wxT("harr"),8596 },
646 { wxT("hearts"),9829 },
647 { wxT("hellip"),8230 },
648 { wxT("iacute"),237 },
649 { wxT("icirc"),238 },
650 { wxT("iexcl"),161 },
651 { wxT("igrave"),236 },
652 { wxT("image"),8465 },
653 { wxT("infin"),8734 },
654 { wxT("int"),8747 },
655 { wxT("iota"),953 },
656 { wxT("iquest"),191 },
657 { wxT("isin"),8712 },
658 { wxT("iuml"),239 },
659 { wxT("kappa"),954 },
660 { wxT("lArr"),8656 },
661 { wxT("lambda"),955 },
662 { wxT("lang"),9001 },
663 { wxT("laquo"),171 },
664 { wxT("larr"),8592 },
665 { wxT("lceil"),8968 },
666 { wxT("ldquo"),8220 },
667 { wxT("le"),8804 },
668 { wxT("lfloor"),8970 },
669 { wxT("lowast"),8727 },
670 { wxT("loz"),9674 },
671 { wxT("lrm"),8206 },
672 { wxT("lsaquo"),8249 },
673 { wxT("lsquo"),8216 },
674 { wxT("lt"),60 },
675 { wxT("macr"),175 },
676 { wxT("mdash"),8212 },
677 { wxT("micro"),181 },
678 { wxT("middot"),183 },
679 { wxT("minus"),8722 },
680 { wxT("mu"),956 },
681 { wxT("nabla"),8711 },
682 { wxT("nbsp"),160 },
683 { wxT("ndash"),8211 },
684 { wxT("ne"),8800 },
685 { wxT("ni"),8715 },
686 { wxT("not"),172 },
687 { wxT("notin"),8713 },
688 { wxT("nsub"),8836 },
689 { wxT("ntilde"),241 },
690 { wxT("nu"),957 },
691 { wxT("oacute"),243 },
692 { wxT("ocirc"),244 },
693 { wxT("oelig"),339 },
694 { wxT("ograve"),242 },
695 { wxT("oline"),8254 },
696 { wxT("omega"),969 },
697 { wxT("omicron"),959 },
698 { wxT("oplus"),8853 },
699 { wxT("or"),8744 },
700 { wxT("ordf"),170 },
701 { wxT("ordm"),186 },
702 { wxT("oslash"),248 },
703 { wxT("otilde"),245 },
704 { wxT("otimes"),8855 },
705 { wxT("ouml"),246 },
706 { wxT("para"),182 },
707 { wxT("part"),8706 },
708 { wxT("permil"),8240 },
709 { wxT("perp"),8869 },
710 { wxT("phi"),966 },
711 { wxT("pi"),960 },
712 { wxT("piv"),982 },
713 { wxT("plusmn"),177 },
714 { wxT("pound"),163 },
715 { wxT("prime"),8242 },
716 { wxT("prod"),8719 },
717 { wxT("prop"),8733 },
718 { wxT("psi"),968 },
719 { wxT("quot"),34 },
720 { wxT("rArr"),8658 },
721 { wxT("radic"),8730 },
722 { wxT("rang"),9002 },
723 { wxT("raquo"),187 },
724 { wxT("rarr"),8594 },
725 { wxT("rceil"),8969 },
726 { wxT("rdquo"),8221 },
727 { wxT("real"),8476 },
728 { wxT("reg"),174 },
729 { wxT("rfloor"),8971 },
730 { wxT("rho"),961 },
731 { wxT("rlm"),8207 },
732 { wxT("rsaquo"),8250 },
733 { wxT("rsquo"),8217 },
734 { wxT("sbquo"),8218 },
735 { wxT("scaron"),353 },
736 { wxT("sdot"),8901 },
737 { wxT("sect"),167 },
738 { wxT("shy"),173 },
739 { wxT("sigma"),963 },
740 { wxT("sigmaf"),962 },
741 { wxT("sim"),8764 },
742 { wxT("spades"),9824 },
743 { wxT("sub"),8834 },
744 { wxT("sube"),8838 },
745 { wxT("sum"),8721 },
746 { wxT("sup"),8835 },
747 { wxT("sup1"),185 },
748 { wxT("sup2"),178 },
749 { wxT("sup3"),179 },
750 { wxT("supe"),8839 },
751 { wxT("szlig"),223 },
752 { wxT("tau"),964 },
753 { wxT("there4"),8756 },
754 { wxT("theta"),952 },
755 { wxT("thetasym"),977 },
756 { wxT("thinsp"),8201 },
757 { wxT("thorn"),254 },
758 { wxT("tilde"),732 },
759 { wxT("times"),215 },
760 { wxT("trade"),8482 },
761 { wxT("uArr"),8657 },
762 { wxT("uacute"),250 },
763 { wxT("uarr"),8593 },
764 { wxT("ucirc"),251 },
765 { wxT("ugrave"),249 },
766 { wxT("uml"),168 },
767 { wxT("upsih"),978 },
768 { wxT("upsilon"),965 },
769 { wxT("uuml"),252 },
770 { wxT("weierp"),8472 },
771 { wxT("xi"),958 },
772 { wxT("yacute"),253 },
773 { wxT("yen"),165 },
774 { wxT("yuml"),255 },
775 { wxT("zeta"),950 },
776 { wxT("zwj"),8205 },
777 { wxT("zwnj"),8204 },
778 {NULL, 0}};
779 static size_t substitutions_cnt = 0;
780
781 if (substitutions_cnt == 0)
782 while (substitutions[substitutions_cnt].code != 0)
783 substitutions_cnt++;
784
785 wxHtmlEntityInfo *info;
786 info = (wxHtmlEntityInfo*) bsearch(entity.c_str(), substitutions,
787 substitutions_cnt,
788 sizeof(wxHtmlEntityInfo),
789 compar_entity);
790 if (info)
791 code = info->code;
792 }
793
794 if (code == 0)
795 return wxT('?');
796 else
797 return GetCharForCode(code);
798 }
799
800 #endif