xCHM  1.23
hhcparser.h
1 /*
2 
3  Copyright (C) 2003 - 2013 Razvan Cojocaru <rzvncj@gmail.com>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  MA 02110-1301, USA.
19 
20 */
21 
22 
23 #ifndef __HHCPARSER_H_
24 #define __HHCPARSER_H_
25 
26 
27 #include <wx/font.h>
28 #include <wx/treectrl.h>
29 #include <string>
30 #include <memory>
31 
32 
33 // Forward declarations.
34 class CHMListCtrl;
35 
36 
38 #define TREE_BUF_SIZE 128
39 
40 
41 
47 struct URLTreeItem : public wxTreeItemData {
48 
50  URLTreeItem(const wxString& str) : _url(str) {}
51 
53  wxString _url;
54 };
55 
56 
58 class HHCParser {
59 
60 public:
62  HHCParser(wxFontEncoding enc, wxTreeCtrl *tree, CHMListCtrl *list);
63 
64 public:
66  void parse(const char* chunk);
67 
68 private:
70  void handleTag(const std::string& tag);
71 
73  bool getParameters(const char* input, std::string& name,
74  std::string& value);
75 
77  void addToTree(const wxString& name, const wxString& value);
78 
80  void addToList(const wxString& name, const wxString& value);
81 
83  wxString replaceHTMLChars(const wxString& input);
84 
86  unsigned getHTMLCode(const wxString& name);
87 
88 private:
90  HHCParser(const HHCParser&);
91 
93  HHCParser& operator=(const HHCParser&);
94 
95 private:
96  int _level;
97  bool _inquote;
98  bool _intag;
99  bool _inobject;
100  std::string _tag;
101  std::string _name;
102  std::string _value;
103  wxTreeCtrl *_tree;
104  CHMListCtrl *_list;
105  wxTreeItemId _parents[TREE_BUF_SIZE];
106  wxFontEncoding _enc;
107  int _counter;
108  std::auto_ptr<wxCSConv> _cvPtr;
109  bool _htmlChars;
110 };
111 
112 
113 #endif // __HHCPARSER_H_
114 
115 
116 /*
117  Local Variables:
118  mode: c++
119  c-basic-offset: 8
120  tab-width: 8
121  c-indent-comments-syntactically-p: t
122  c-tab-always-indent: t
123  indent-tabs-mode: t
124  End:
125 */
126 
127 // vim:shiftwidth=8:autoindent:tabstop=8:noexpandtab:softtabstop=8
128 
URLTreeItem(const wxString &str)
Sets the data to str.
Definition: hhcparser.h:50
void parse(const char *chunk)
Parse a chunk of data.
Definition: hhcparser.cpp:160
unsigned getHTMLCode(const wxString &name)
HTML code for given name (if available)
Definition: hhcparser.cpp:445
wxString replaceHTMLChars(const wxString &input)
Replace special HTML strings with correct code.
Definition: hhcparser.cpp:402
void addToList(const wxString &name, const wxString &value)
Add the information to the index list.
Definition: hhcparser.cpp:392
HHCParser & operator=(const HHCParser &)
Prevent copying, we have an auto_ptr&lt;&gt; member.
HHCParser(wxFontEncoding enc, wxTreeCtrl *tree, CHMListCtrl *list)
Constructor.
Definition: hhcparser.cpp:147
void handleTag(const std::string &tag)
Handle a retrieved tag. I&#39;m only interested in very few tags.
Definition: hhcparser.cpp:193
Objects of this class will be used as opaque data to be used with a tree item, so that when the user ...
Definition: hhcparser.h:47
List control class meant to emulate the look and feel of a wxListBox.
Definition: chmlistctrl.h:65
wxString _url
Useful data.
Definition: hhcparser.h:53
void addToTree(const wxString &name, const wxString &value)
Add the information to the contents tree.
Definition: hhcparser.cpp:362
Fast index/contents file parser.
Definition: hhcparser.h:58
bool getParameters(const char *input, std::string &name, std::string &value)
Retrieve a parameter name.
Definition: hhcparser.cpp:280