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