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