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