]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlparser.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlparser.cpp
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation
14 #include <wx/wxprec.h>
27 #include <wx/tokenzr.h>
28 #include <wx/wfstream.h>
30 #include <wx/html/htmldefs.h>
31 #include <wx/html/htmlparser.h>
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser
,wxObject
)
42 wxObject
* wxHtmlParser::Parse(const wxString
& source
)
48 result
= GetProduct();
55 void wxHtmlParser::InitParser(const wxString
& source
)
58 m_Cache
= new wxHtmlTagsCache(m_Source
);
63 void wxHtmlParser::DoneParser()
71 #define HTML_MAX_BUFLEN 1024
73 void wxHtmlParser::DoParsing(int begin_pos
, int end_pos
)
75 char temp
[HTML_BUFLEN
], c
;
85 // continue building word:
88 if (templen
== HTML_BUFLEN
-1) {
97 wxHtmlTag
tag(m_Source
, i
, end_pos
, m_Cache
);
105 if (tag
.HasEnding()) i
= tag
.GetEndPos2();
106 else i
= tag
.GetBeginPos();
110 if (templen
) { // last word of block :-(
118 void wxHtmlParser::AddTag(const wxHtmlTag
& tag
)
123 h
= (wxHtmlTagHandler
*) m_HandlersHash
.Get(tag
.GetName());
125 inner
= h
-> HandleTag(tag
);
128 DoParsing(tag
.GetBeginPos(), tag
.GetEndPos1());
134 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler
*handler
)
136 wxString
s(handler
-> GetSupportedTags());
137 wxStringTokenizer
tokenizer(s
, ", ");
139 #if (wxVERSION_NUMBER < 2100)
140 while (tokenizer
.HasMoreToken())
142 while (tokenizer
.HasMoreTokens())
144 m_HandlersHash
.Put(tokenizer
.NextToken(), handler
);
146 if (m_HandlersList
.IndexOf(handler
) == wxNOT_FOUND
)
147 m_HandlersList
.Append(handler
);
149 handler
-> SetParser(this);
154 wxHtmlParser::~wxHtmlParser()
156 m_HandlersHash
.Clear();
157 m_HandlersList
.DeleteContents(TRUE
);
158 m_HandlersList
.Clear();
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
167 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)