]>
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
)
75 if (end_pos
<= begin_pos
) return;
78 char *temp
= new char[end_pos
- begin_pos
+ 1];
86 c
= m_Source
[(unsigned int) i
];
88 // continue building word:
95 wxHtmlTag
tag(m_Source
, i
, end_pos
, m_Cache
);
103 if (tag
.HasEnding()) i
= tag
.GetEndPos2();
104 else i
= tag
.GetBeginPos();
108 if (templen
) { // last word of block :-(
117 void wxHtmlParser::AddTag(const wxHtmlTag
& tag
)
122 h
= (wxHtmlTagHandler
*) m_HandlersHash
.Get(tag
.GetName());
124 inner
= h
-> HandleTag(tag
);
127 DoParsing(tag
.GetBeginPos(), tag
.GetEndPos1());
133 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler
*handler
)
135 wxString
s(handler
-> GetSupportedTags());
136 wxStringTokenizer
tokenizer(s
, ", ");
138 while (tokenizer
.HasMoreTokens())
139 m_HandlersHash
.Put(tokenizer
.NextToken(), handler
);
141 if (m_HandlersList
.IndexOf(handler
) == wxNOT_FOUND
)
142 m_HandlersList
.Append(handler
);
144 handler
-> SetParser(this);
149 void wxHtmlParser::PushTagHandler(wxHtmlTagHandler
*handler
, wxString tags
)
151 wxStringTokenizer
tokenizer(tags
, ", ");
154 if (m_HandlersStack
== NULL
) {
155 m_HandlersStack
= new wxList
;
156 m_HandlersStack
-> DeleteContents(TRUE
);
159 m_HandlersStack
-> Insert(new wxHashTable(m_HandlersHash
));
161 while (tokenizer
.HasMoreTokens()) {
162 key
= tokenizer
.NextToken();
163 m_HandlersHash
.Delete(key
);
164 m_HandlersHash
.Put(key
, handler
);
170 void wxHtmlParser::PopTagHandler()
174 if (m_HandlersStack
== NULL
||
175 (first
= m_HandlersStack
-> GetFirst()) == NULL
)
177 wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
180 m_HandlersHash
= *((wxHashTable
*) first
-> GetData());
181 m_HandlersStack
-> DeleteNode(first
);
186 wxHtmlParser::~wxHtmlParser()
188 if (m_HandlersStack
) delete m_HandlersStack
;
189 m_HandlersHash
.Clear();
190 m_HandlersList
.DeleteContents(TRUE
);
191 m_HandlersList
.Clear();
196 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
200 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)