]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlpars.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation
15 #include <wx/wxprec.h>
28 #include "wx/tokenzr.h"
29 #include "wx/wfstream.h"
31 #include "wx/html/htmldefs.h"
32 #include "wx/html/htmlpars.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser
,wxObject
)
43 wxObject
* wxHtmlParser::Parse(const wxString
& source
)
49 result
= GetProduct();
56 void wxHtmlParser::InitParser(const wxString
& source
)
59 m_Cache
= new wxHtmlTagsCache(m_Source
);
64 void wxHtmlParser::DoneParser()
72 #define HTML_MAX_BUFLEN 1024
74 void wxHtmlParser::DoParsing(int begin_pos
, int end_pos
)
76 char temp
[HTML_BUFLEN
], c
;
86 // continue building word:
89 if (templen
== HTML_BUFLEN
-1) {
98 wxHtmlTag
tag(m_Source
, i
, end_pos
, m_Cache
);
106 if (tag
.HasEnding()) i
= tag
.GetEndPos2();
107 else i
= tag
.GetBeginPos();
111 if (templen
) { // last word of block :-(
119 void wxHtmlParser::AddTag(const wxHtmlTag
& tag
)
124 h
= (wxHtmlTagHandler
*) m_HandlersHash
.Get(tag
.GetName());
126 inner
= h
-> HandleTag(tag
);
129 DoParsing(tag
.GetBeginPos(), tag
.GetEndPos1());
135 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler
*handler
)
137 wxString
s(handler
-> GetSupportedTags());
138 wxStringTokenizer
tokenizer(s
, ", ");
140 while (tokenizer
.HasMoreTokens())
141 m_HandlersHash
.Put(tokenizer
.NextToken(), handler
);
143 if (m_HandlersList
.IndexOf(handler
) == wxNOT_FOUND
)
144 m_HandlersList
.Append(handler
);
146 handler
-> SetParser(this);
151 wxHtmlParser::~wxHtmlParser()
153 m_HandlersHash
.Clear();
154 m_HandlersList
.DeleteContents(TRUE
);
155 m_HandlersList
.Clear();
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
164 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)