]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/htmlpars.cpp
Further fixes to references
[wxWidgets.git] / src / html / htmlpars.cpp
index 64054fc2d2f246bdf211e123bd3d607688c28cc0..69be9d281e2f9af2702033b5c25282fe92702ce6 100644 (file)
@@ -80,8 +80,9 @@ wxHtmlParser::wxHtmlParser()
 
 wxHtmlParser::~wxHtmlParser()
 {
-    while (RestoreState())
-        DestroyDOMTree();
+    while (RestoreState()) {}
+    DestroyDOMTree();
+    
     delete m_HandlersStack;
     m_HandlersHash.Clear();
     m_HandlersList.DeleteContents(TRUE);
@@ -271,8 +272,9 @@ void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
              pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
         {
             // Add text:
-            AddText(m_Source.Mid(pieces[m_CurTextPiece].m_pos,
-                                 pieces[m_CurTextPiece].m_lng));
+            AddText(GetEntitiesParser()->Parse(
+                       m_Source.Mid(pieces[m_CurTextPiece].m_pos,
+                                    pieces[m_CurTextPiece].m_lng)));
             begin_pos = pieces[m_CurTextPiece].m_pos +
                         pieces[m_CurTextPiece].m_lng;
             m_CurTextPiece++;
@@ -316,7 +318,7 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
     wxStringTokenizer tokenizer(s, wxT(", "));
 
     while (tokenizer.HasMoreTokens())
-        m_HandlersHash.Put(tokenizer.NextToken(), handler);
+        m_HandlersHash.Put(tokenizer.GetNextToken(), handler);
 
     if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
         m_HandlersList.Append(handler);
@@ -339,7 +341,7 @@ void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags)
 
     while (tokenizer.HasMoreTokens())
     {
-        key = tokenizer.NextToken();
+        key = tokenizer.GetNextToken();
         m_HandlersHash.Delete(key);
         m_HandlersHash.Put(key, handler);
     }
@@ -385,6 +387,8 @@ bool wxHtmlParser::RestoreState()
 {
     if (!m_SavedStates) return FALSE;
 
+    DestroyDOMTree();
+
     wxHtmlParserState *s = m_SavedStates;
     m_SavedStates = s->m_nextState;
 
@@ -444,6 +448,8 @@ wxString wxHtmlEntitiesParser::Parse(const wxString& input)
     const wxChar *c, *last;
     const wxChar *in_str = input.c_str();
     wxString output;
+    
+    output.reserve(input.length());
 
     for (c = in_str, last = in_str; *c != wxT('\0'); c++)
     {
@@ -452,8 +458,11 @@ wxString wxHtmlEntitiesParser::Parse(const wxString& input)
             if (c - last > 0)
                 output.append(last, c - last);
             if (++c == wxT('\0')) break;
+        
             wxString entity;
             const wxChar *ent_s = c;
+            wxChar entity_char;
+        
             for (; (*c >= wxT('a') && *c <= wxT('z')) ||
                    (*c >= wxT('A') && *c <= wxT('Z')) ||
                    (*c >= wxT('0') && *c <= wxT('9')) ||
@@ -461,7 +470,14 @@ wxString wxHtmlEntitiesParser::Parse(const wxString& input)
             entity.append(ent_s, c - ent_s);
             if (*c != wxT(';')) c--;
             last = c+1;
-            output << GetEntityChar(entity);
+            entity_char = GetEntityChar(entity);
+            if (entity_char)
+                output << entity_char;
+            else
+            {
+                output.append(ent_s-1, c-ent_s+2);
+                wxLogDebug(wxT("Unrecognized HTML entity: '%s'"), entity.c_str());
+            }
         }
     }
     if (*last != wxT('\0'))
@@ -475,7 +491,7 @@ struct wxHtmlEntityInfo
     unsigned code;
 };
 
-static int LINKAGEMODE compar_entity(const void *key, const void *item)
+extern "C" int LINKAGEMODE wxHtmlEntityCompare(const void *key, const void *item)
 {
     return wxStrcmp((wxChar*)key, ((wxHtmlEntityInfo*)item)->name);
 }
@@ -785,15 +801,21 @@ wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity)
         info = (wxHtmlEntityInfo*) bsearch(entity.c_str(), substitutions,
                                            substitutions_cnt,
                                            sizeof(wxHtmlEntityInfo),
-                                           compar_entity);
+                                           wxHtmlEntityCompare);
         if (info)
             code = info->code;
     }
 
     if (code == 0)
-        return wxT('?');
+        return 0;
     else
         return GetCharForCode(code);
 }
 
+wxFSFile *wxHtmlParser::OpenURL(wxHtmlURLType WXUNUSED(type), 
+                                const wxString& url) const
+{
+    return GetFS()->OpenFile(url);
+}
+
 #endif