]>
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];
87 c
= m_Source
[(unsigned int) i
];
89 // continue building word:
98 wxHtmlTag
tag(m_Source
, i
, end_pos
, m_Cache
);
107 if (tag
.HasEnding()) i
= tag
.GetEndPos2();
108 else i
= tag
.GetBeginPos();
113 { // last word of block :-(
122 void wxHtmlParser::AddTag(const wxHtmlTag
& tag
)
127 h
= (wxHtmlTagHandler
*) m_HandlersHash
.Get(tag
.GetName());
129 inner
= h
->HandleTag(tag
);
133 DoParsing(tag
.GetBeginPos(), tag
.GetEndPos1());
139 void wxHtmlParser::AddTagHandler(wxHtmlTagHandler
*handler
)
141 wxString
s(handler
->GetSupportedTags());
142 wxStringTokenizer
tokenizer(s
, ", ");
144 while (tokenizer
.HasMoreTokens())
145 m_HandlersHash
.Put(tokenizer
.NextToken(), handler
);
147 if (m_HandlersList
.IndexOf(handler
) == wxNOT_FOUND
)
148 m_HandlersList
.Append(handler
);
150 handler
->SetParser(this);
155 void wxHtmlParser::PushTagHandler(wxHtmlTagHandler
*handler
, wxString tags
)
157 wxStringTokenizer
tokenizer(tags
, ", ");
160 if (m_HandlersStack
== NULL
)
162 m_HandlersStack
= new wxList
;
163 m_HandlersStack
->DeleteContents(TRUE
);
166 m_HandlersStack
->Insert(new wxHashTable(m_HandlersHash
));
168 while (tokenizer
.HasMoreTokens())
170 key
= tokenizer
.NextToken();
171 m_HandlersHash
.Delete(key
);
172 m_HandlersHash
.Put(key
, handler
);
178 void wxHtmlParser::PopTagHandler()
182 if (m_HandlersStack
== NULL
||
183 (first
= m_HandlersStack
->GetFirst()) == NULL
)
185 wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
188 m_HandlersHash
= *((wxHashTable
*) first
->GetData());
189 m_HandlersStack
->DeleteNode(first
);
194 wxHtmlParser::~wxHtmlParser()
196 if (m_HandlersStack
) delete m_HandlersStack
;
197 m_HandlersHash
.Clear();
198 m_HandlersList
.DeleteContents(TRUE
);
199 m_HandlersList
.Clear();
204 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
208 IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler
,wxObject
)