2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef __HTMLREADER_H__
21 #define __HTMLREADER_H__
26 #include <ZLEncodingConverter.h>
27 #include "../EncodedTextReader.h"
31 class HtmlReader
: public EncodedTextReader
{
34 struct HtmlAttribute
{
39 HtmlAttribute(const std::string
&name
);
41 void setValue(const std::string
&value
);
48 std::vector
<HtmlAttribute
> Attributes
;
52 void addAttribute(const std::string
&name
);
53 void setLastAttributeValue(const std::string
&value
);
56 HtmlTag(const HtmlTag
&);
57 const HtmlTag
&operator= (const HtmlTag
&);
61 static void setTag(HtmlTag
&tag
, const std::string
&fullName
);
64 virtual void readDocument(ZLInputStream
&stream
);
67 HtmlReader(const std::string
&encoding
);
68 virtual ~HtmlReader();
71 virtual void startDocumentHandler() = 0;
72 virtual void endDocumentHandler() = 0;
74 virtual bool tagHandler(const HtmlTag
&tag
) = 0;
75 virtual bool characterDataHandler(const char *text
, int len
, bool convert
) = 0;
78 void appendString(std::string
&to
, std::string
&from
);
81 inline HtmlReader::HtmlAttribute::HtmlAttribute(const std::string
&name
) : Name(name
), HasValue(false) {}
82 inline HtmlReader::HtmlAttribute::~HtmlAttribute() {}
83 inline void HtmlReader::HtmlAttribute::setValue(const std::string
&value
) { Value
= value
; HasValue
= true; }
85 inline HtmlReader::HtmlTag::HtmlTag() : Start(true) {}
86 inline HtmlReader::HtmlTag::~HtmlTag() {}
87 inline void HtmlReader::HtmlTag::addAttribute(const std::string
&name
) { Attributes
.push_back(HtmlAttribute(name
)); }
88 inline void HtmlReader::HtmlTag::setLastAttributeValue(const std::string
&value
) { if (!Attributes
.empty()) Attributes
.back().setValue(value
); }
90 #endif /* __HTMLREADER_H__ */