]>
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 wxHTML_MAX_BUFLEN 1024
74 void wxHtmlParser::DoParsing(int begin_pos
, int end_pos
)
76 char temp
[wxHTML_BUFLEN
], c
;
86 // continue building word:
89 if (templen
== wxHTML_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 void wxHtmlParser::PushTagHandler(wxHtmlTagHandler
*handler
, wxString tags
)
153 wxStringTokenizer
tokenizer(tags
, ", ");
156 if (m_HandlersStack
== NULL
) {
157 m_HandlersStack
= new wxList
;
158 m_HandlersStack
-> DeleteContents(TRUE
);
161 m_HandlersStack
-> Insert(new wxHashTable(m_HandlersHash
));
163 while (tokenizer
.HasMoreTokens()) {
164 key
= tokenizer
.NextToken();
165 m_HandlersHash
.Delete(key
);
166 m_HandlersHash
.Put(key
, handler
);
172 void wxHtmlParser::PopTagHandler()
176 if (m_HandlersStack
== NULL
|| (first
= m_HandlersStack
-> GetFirst()) == NULL
) return;
177 m_HandlersHash
= *((wxHashTable
*) first
-> GetData());
178 m_HandlersStack
-> DeleteNode(first
);
183 wxHtmlParser::~wxHtmlParser()
185 if (m_HandlersStack
) delete m_HandlersStack
;
186 m_HandlersHash
.Clear();
187 m_HandlersList
.DeleteContents(TRUE
);
188 m_HandlersList
.Clear();
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
197 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)