]> git.saurik.com Git - wxWidgets.git/blame - src/html/htmlpars.cpp
made GetColourFromGTKWidget() more general, it is now used for all colours
[wxWidgets.git] / src / html / htmlpars.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
69941f05 2// Name: htmlpars.cpp
5526e819
VS
3// Purpose: wxHtmlParser class (generic parser)
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation
13#endif
14
3096bd2f 15#include "wx/wxprec.h"
5526e819
VS
16
17#include "wx/defs.h"
f6bcfd97 18#if wxUSE_HTML && wxUSE_STREAMS
5526e819
VS
19
20#ifdef __BORDLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WXPRECOMP
04dbb646
VZ
25 #include "wx/log.h"
26 #include "wx/intl.h"
5526e819
VS
27#endif
28
69941f05
VS
29#include "wx/tokenzr.h"
30#include "wx/wfstream.h"
31#include "wx/url.h"
daa616fc 32#include "wx/fontmap.h"
69941f05
VS
33#include "wx/html/htmldefs.h"
34#include "wx/html/htmlpars.h"
211dfedd
VS
35#include "wx/dynarray.h"
36#include "wx/arrimpl.cpp"
5526e819 37
211dfedd
VS
38//-----------------------------------------------------------------------------
39// wxHtmlParser helpers
40//-----------------------------------------------------------------------------
41
42class wxHtmlTextPiece
43{
44public:
45 wxHtmlTextPiece(int pos, int lng) : m_pos(pos), m_lng(lng) {}
46 int m_pos, m_lng;
47};
48
49WX_DECLARE_OBJARRAY(wxHtmlTextPiece, wxHtmlTextPieces);
50WX_DEFINE_OBJARRAY(wxHtmlTextPieces);
5526e819 51
481c879b 52class wxHtmlParserState
211dfedd 53{
481c879b 54public:
211dfedd
VS
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};
5526e819
VS
62
63//-----------------------------------------------------------------------------
64// wxHtmlParser
65//-----------------------------------------------------------------------------
66
67IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
68
04dbb646 69wxHtmlParser::wxHtmlParser()
211dfedd 70 : wxObject(), m_HandlersHash(wxKEY_STRING),
daa616fc
VS
71 m_FS(NULL), m_HandlersStack(NULL)
72{
73 m_entitiesParser = new wxHtmlEntitiesParser;
211dfedd
VS
74 m_Tags = NULL;
75 m_CurTag = NULL;
76 m_TextPieces = NULL;
77 m_CurTextPiece = 0;
78 m_SavedStates = NULL;
daa616fc
VS
79}
80
81wxHtmlParser::~wxHtmlParser()
82{
211dfedd
VS
83 while (RestoreState())
84 DestroyDOMTree();
daa616fc
VS
85 delete m_HandlersStack;
86 m_HandlersHash.Clear();
87 m_HandlersList.DeleteContents(TRUE);
88 m_HandlersList.Clear();
89 delete m_entitiesParser;
90}
5526e819
VS
91
92wxObject* 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
5526e819
VS
103void wxHtmlParser::InitParser(const wxString& source)
104{
1309ba6c 105 SetSource(source);
5526e819 106}
1309ba6c 107
5526e819
VS
108void wxHtmlParser::DoneParser()
109{
211dfedd 110 DestroyDOMTree();
5526e819
VS
111}
112
1309ba6c
VS
113void wxHtmlParser::SetSource(const wxString& src)
114{
211dfedd 115 DestroyDOMTree();
1309ba6c 116 m_Source = src;
211dfedd
VS
117 CreateDOMTree();
118 m_CurTag = NULL;
119 m_CurTextPiece = 0;
1309ba6c 120}
5526e819 121
211dfedd 122void wxHtmlParser::CreateDOMTree()
5526e819 123{
211dfedd
VS
124 wxHtmlTagsCache cache(m_Source);
125 m_TextPieces = new wxHtmlTextPieces;
126 CreateDOMSubTree(NULL, 0, m_Source.Length(), &cache);
127 m_CurTextPiece = 0;
128}
5526e819 129
211dfedd
VS
130void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur,
131 int begin_pos, int end_pos,
132 wxHtmlTagsCache *cache)
133{
134 if (end_pos <= begin_pos) return;
5526e819 135
211dfedd
VS
136 wxChar c;
137 int i = begin_pos;
138 int textBeginning = begin_pos;
d699f48b 139
04dbb646 140 while (i < end_pos)
4f9297b0 141 {
211dfedd 142 c = m_Source.GetChar(i);
5526e819 143
211dfedd
VS
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++);
d699f48b 163 if ((c == wxT(' ') || c == wxT('\n') ||
211dfedd
VS
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++;
d699f48b 172 else
211dfedd
VS
173 dashes = 0;
174 }
175 }
d699f48b 176
211dfedd
VS
177 // add another tag to the tree:
178 else if (i < end_pos-1 && m_Source.GetChar(i+1) != wxT('/'))
4f9297b0 179 {
211dfedd 180 wxHtmlTag *chd;
d699f48b
KB
181 if (cur)
182 chd = new wxHtmlTag(cur, m_Source,
211dfedd 183 i, end_pos, cache, m_entitiesParser);
d699f48b 184 else
211dfedd
VS
185 {
186 chd = new wxHtmlTag(NULL, m_Source,
187 i, end_pos, cache, m_entitiesParser);
d699f48b 188 if (!m_Tags)
211dfedd 189 {
d699f48b 190 // if this is the first tag to be created make the root
211dfedd
VS
191 // m_Tags point to it:
192 m_Tags = chd;
193 }
194 else
195 {
d699f48b 196 // if there is already a root tag add this tag as
211dfedd
VS
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,
d699f48b 206 chd->GetBeginPos(), chd->GetEndPos1(),
211dfedd
VS
207 cache);
208 i = chd->GetEndPos2();
209 }
210 else
211 i = chd->GetBeginPos();
212 textBeginning = i;
213 }
214
215 // ... or skip ending tag:
d699f48b 216 else
211dfedd
VS
217 {
218 while (i < end_pos && m_Source.GetChar(i) != wxT('>')) i++;
219 textBeginning = i+1;
5526e819 220 }
5526e819 221 }
211dfedd 222 else i++;
5526e819
VS
223 }
224
211dfedd
VS
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
231void 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
d699f48b 247void wxHtmlParser::DoParsing()
211dfedd
VS
248{
249 m_CurTag = m_Tags;
250 m_CurTextPiece = 0;
d699f48b 251 DoParsing(0, m_Source.Length());
211dfedd
VS
252}
253
254void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
255{
256 if (end_pos <= begin_pos) return;
d699f48b 257
211dfedd
VS
258 wxHtmlTextPieces& pieces = *m_TextPieces;
259 size_t piecesCnt = pieces.GetCount();
d699f48b 260
211dfedd
VS
261 while (begin_pos < end_pos)
262 {
263 while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
264 m_CurTag = m_CurTag->GetNextTag();
d699f48b 265 while (m_CurTextPiece < piecesCnt &&
211dfedd
VS
266 pieces[m_CurTextPiece].m_pos < begin_pos)
267 m_CurTextPiece++;
268
d699f48b
KB
269 if (m_CurTextPiece < piecesCnt &&
270 (!m_CurTag ||
211dfedd
VS
271 pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
272 {
273 // Add text:
f23e92e7
VS
274 AddText(GetEntitiesParser()->Parse(
275 m_Source.Mid(pieces[m_CurTextPiece].m_pos,
276 pieces[m_CurTextPiece].m_lng)));
d699f48b 277 begin_pos = pieces[m_CurTextPiece].m_pos +
211dfedd
VS
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();
d699f48b 288 else
211dfedd
VS
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;
5526e819
VS
296 }
297}
298
5526e819
VS
299void 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)
4f9297b0 306 inner = h->HandleTag(tag);
04dbb646 307 if (!inner)
4f9297b0 308 {
5526e819
VS
309 if (tag.HasEnding())
310 DoParsing(tag.GetBeginPos(), tag.GetEndPos1());
311 }
312}
313
5526e819
VS
314void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
315{
4f9297b0 316 wxString s(handler->GetSupportedTags());
211dfedd 317 wxStringTokenizer tokenizer(s, wxT(", "));
5526e819 318
5526e819 319 while (tokenizer.HasMoreTokens())
5526e819
VS
320 m_HandlersHash.Put(tokenizer.NextToken(), handler);
321
322 if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
323 m_HandlersList.Append(handler);
324
4f9297b0 325 handler->SetParser(this);
5526e819
VS
326}
327
a7a4d01b
VS
328void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags)
329{
211dfedd 330 wxStringTokenizer tokenizer(tags, wxT(", "));
a7a4d01b
VS
331 wxString key;
332
04dbb646 333 if (m_HandlersStack == NULL)
4f9297b0 334 {
a7a4d01b 335 m_HandlersStack = new wxList;
4f9297b0 336 m_HandlersStack->DeleteContents(TRUE);
a7a4d01b
VS
337 }
338
4f9297b0 339 m_HandlersStack->Insert(new wxHashTable(m_HandlersHash));
a7a4d01b 340
04dbb646 341 while (tokenizer.HasMoreTokens())
4f9297b0 342 {
a7a4d01b
VS
343 key = tokenizer.NextToken();
344 m_HandlersHash.Delete(key);
345 m_HandlersHash.Put(key, handler);
346 }
347}
348
a7a4d01b
VS
349void wxHtmlParser::PopTagHandler()
350{
351 wxNode *first;
04dbb646
VZ
352
353 if (m_HandlersStack == NULL ||
354 (first = m_HandlersStack->GetFirst()) == NULL)
f3c82859
VS
355 {
356 wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
357 return;
358 }
4f9297b0
VS
359 m_HandlersHash = *((wxHashTable*) first->GetData());
360 m_HandlersStack->DeleteNode(first);
a7a4d01b
VS
361}
362
211dfedd
VS
363void 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;
d699f48b 381
211dfedd
VS
382 SetSource(src);
383}
384
385bool wxHtmlParser::RestoreState()
386{
387 if (!m_SavedStates) return FALSE;
d699f48b 388
211dfedd
VS
389 wxHtmlParserState *s = m_SavedStates;
390 m_SavedStates = s->m_nextState;
d699f48b 391
211dfedd
VS
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;
d699f48b 397
211dfedd
VS
398 delete s;
399 return TRUE;
400}
401
5526e819
VS
402//-----------------------------------------------------------------------------
403// wxHtmlTagHandler
404//-----------------------------------------------------------------------------
405
406IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler,wxObject)
daa616fc
VS
407
408
409//-----------------------------------------------------------------------------
410// wxHtmlEntitiesParser
411//-----------------------------------------------------------------------------
412
413IMPLEMENT_DYNAMIC_CLASS(wxHtmlEntitiesParser,wxObject)
414
415wxHtmlEntitiesParser::wxHtmlEntitiesParser()
416#if wxUSE_WCHAR_T && !wxUSE_UNICODE
417 : m_conv(NULL), m_encoding(wxFONTENCODING_SYSTEM)
223d09f6 418#endif
daa616fc
VS
419{
420}
421
422wxHtmlEntitiesParser::~wxHtmlEntitiesParser()
423{
5438a566 424#if wxUSE_WCHAR_T && !wxUSE_UNICODE
daa616fc 425 delete m_conv;
5438a566 426#endif
daa616fc 427}
5526e819 428
daa616fc
VS
429void 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));
d699f48b
KB
438#else
439 (void) encoding;
daa616fc
VS
440#endif
441}
442
443wxString wxHtmlEntitiesParser::Parse(const wxString& input)
444{
445 const wxChar *c, *last;
446 const wxChar *in_str = input.c_str();
447 wxString output;
04dbb646 448
daa616fc
VS
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);
211dfedd
VS
463 if (*c != wxT(';')) c--;
464 last = c+1;
daa616fc 465 output << GetEntityChar(entity);
daa616fc
VS
466 }
467 }
468 if (*last != wxT('\0'))
469 output.append(last);
470 return output;
471}
472
473struct wxHtmlEntityInfo
474{
475 const wxChar *name;
476 unsigned code;
477};
478
53776059 479static int LINKAGEMODE compar_entity(const void *key, const void *item)
daa616fc
VS
480{
481 return wxStrcmp((wxChar*)key, ((wxHtmlEntityInfo*)item)->name);
482}
483
484wxChar 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;
eaf1a1d9 494 if (conv->WC2MB(buf, wbuf, 2) == (size_t)-1)
daa616fc
VS
495 return '?';
496 return buf[0];
497#else
498 return (code < 256) ? (wxChar)code : '?';
499#endif
500}
501
502wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity)
503{
504 unsigned code = 0;
04dbb646 505
daa616fc
VS
506 if (entity[0] == wxT('#'))
507 {
508 const wxChar *ent_s = entity.c_str();
509 const wxChar *format;
04dbb646 510
daa616fc
VS
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;
04dbb646 780
daa616fc
VS
781 if (substitutions_cnt == 0)
782 while (substitutions[substitutions_cnt].code != 0)
783 substitutions_cnt++;
784
785 wxHtmlEntityInfo *info;
04dbb646 786 info = (wxHtmlEntityInfo*) bsearch(entity.c_str(), substitutions,
daa616fc
VS
787 substitutions_cnt,
788 sizeof(wxHtmlEntityInfo),
789 compar_entity);
790 if (info)
791 code = info->code;
792 }
04dbb646 793
daa616fc
VS
794 if (code == 0)
795 return wxT('?');
796 else
797 return GetCharForCode(code);
798}
799
800#endif