]>
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"
18 #if wxUSE_HTML && wxUSE_STREAMS
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()
73 void wxHtmlParser::DoParsing(int begin_pos
, int end_pos
)
76 char *temp
= new char[end_pos
- begin_pos
+ 1];
84 c
= m_Source
[(unsigned int) i
];
86 // continue building word:
93 wxHtmlTag
tag(m_Source
, i
, end_pos
, m_Cache
);
101 if (tag
.HasEnding()) i
= tag
.GetEndPos2();
102 else i
= tag
.GetBeginPos();
106 if (templen
) { // last word of block :-(
115 void wxHtmlParser::AddTag(const wxHtmlTag
& tag
)
120 h
= (wxHtmlTagHandler
*) m_HandlersHash
.Get(tag
.GetName());
122 inner
= h
-> HandleTag(tag
);
125 DoParsing(tag
.GetBeginPos(), tag
.GetEndPos1());
131 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler
*handler
)
133 wxString
s(handler
-> GetSupportedTags());
134 wxStringTokenizer
tokenizer(s
, ", ");
136 while (tokenizer
.HasMoreTokens())
137 m_HandlersHash
.Put(tokenizer
.NextToken(), handler
);
139 if (m_HandlersList
.IndexOf(handler
) == wxNOT_FOUND
)
140 m_HandlersList
.Append(handler
);
142 handler
-> SetParser(this);
147 void wxHtmlParser::PushTagHandler(wxHtmlTagHandler
*handler
, wxString tags
)
149 wxStringTokenizer
tokenizer(tags
, ", ");
152 if (m_HandlersStack
== NULL
) {
153 m_HandlersStack
= new wxList
;
154 m_HandlersStack
-> DeleteContents(TRUE
);
157 m_HandlersStack
-> Insert(new wxHashTable(m_HandlersHash
));
159 while (tokenizer
.HasMoreTokens()) {
160 key
= tokenizer
.NextToken();
161 m_HandlersHash
.Delete(key
);
162 m_HandlersHash
.Put(key
, handler
);
168 void wxHtmlParser::PopTagHandler()
172 if (m_HandlersStack
== NULL
||
173 (first
= m_HandlersStack
-> GetFirst()) == NULL
)
175 wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
178 m_HandlersHash
= *((wxHashTable
*) first
-> GetData());
179 m_HandlersStack
-> DeleteNode(first
);
184 wxHtmlParser::~wxHtmlParser()
186 if (m_HandlersStack
) delete m_HandlersStack
;
187 m_HandlersHash
.Clear();
188 m_HandlersList
.DeleteContents(TRUE
);
189 m_HandlersList
.Clear();
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
198 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)