]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmltag.h
fixed wxHTML parsing to run in O(n) even in UTF8 build
[wxWidgets.git] / include / wx / html / htmltag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmltag.h
3 // Purpose: wxHtmlTag class (represents single tag)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_HTMLTAG_H_
11 #define _WX_HTMLTAG_H_
12
13 #include "wx/defs.h"
14
15 #if wxUSE_HTML
16
17 #include "wx/object.h"
18 #include "wx/arrstr.h"
19
20 class WXDLLIMPEXP_FWD_CORE wxColour;
21 class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
22
23 //-----------------------------------------------------------------------------
24 // wxHtmlTagsCache
25 // - internal wxHTML class, do not use!
26 //-----------------------------------------------------------------------------
27
28 class wxHtmlTagsCacheData;
29
30 class WXDLLIMPEXP_HTML wxHtmlTagsCache
31 {
32 private:
33 wxHtmlTagsCacheData *m_Cache;
34 int m_CachePos;
35
36 wxHtmlTagsCacheData& Cache() { return *m_Cache; }
37
38 public:
39 wxHtmlTagsCache() {m_Cache = NULL;}
40 wxHtmlTagsCache(const wxString& source);
41 virtual ~wxHtmlTagsCache();
42
43 // Finds parameters for tag starting at at and fills the variables
44 void QueryTag(const wxString::const_iterator& at,
45 const wxString::const_iterator& inputEnd,
46 wxString::const_iterator *end1,
47 wxString::const_iterator *end2,
48 bool *hasEnding);
49
50 DECLARE_NO_COPY_CLASS(wxHtmlTagsCache)
51 };
52
53
54 //--------------------------------------------------------------------------------
55 // wxHtmlTag
56 // This represents single tag. It is used as internal structure
57 // by wxHtmlParser.
58 //--------------------------------------------------------------------------------
59
60 class WXDLLIMPEXP_HTML wxHtmlTag
61 {
62 protected:
63 // constructs wxHtmlTag object based on HTML tag.
64 // The tag begins (with '<' character) at position pos in source
65 // end_pos is position where parsing ends (usually end of document)
66 wxHtmlTag(wxHtmlTag *parent,
67 const wxString *source,
68 const wxString::const_iterator& pos,
69 const wxString::const_iterator& end_pos,
70 wxHtmlTagsCache *cache,
71 wxHtmlEntitiesParser *entParser);
72 friend class wxHtmlParser;
73 public:
74 ~wxHtmlTag();
75
76 wxHtmlTag *GetParent() const {return m_Parent;}
77 wxHtmlTag *GetFirstSibling() const;
78 wxHtmlTag *GetLastSibling() const;
79 wxHtmlTag *GetChildren() const { return m_FirstChild; }
80 wxHtmlTag *GetPreviousSibling() const { return m_Prev; }
81 wxHtmlTag *GetNextSibling() const {return m_Next; }
82 // Return next tag, as if tree had been flattened
83 wxHtmlTag *GetNextTag() const;
84
85 // Returns tag's name in uppercase.
86 inline wxString GetName() const {return m_Name;}
87
88 // Returns true if the tag has given parameter. Parameter
89 // should always be in uppercase.
90 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
91 bool HasParam(const wxString& par) const;
92
93 // Returns value of the param. Value is in uppercase unless it is
94 // enclosed with "
95 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
96 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
97 // (or ("WhaT.jpg") if with_commas == true)
98 wxString GetParam(const wxString& par, bool with_commas = false) const;
99
100 // Convenience functions:
101 bool GetParamAsColour(const wxString& par, wxColour *clr) const;
102 bool GetParamAsInt(const wxString& par, int *clr) const;
103
104 // Scans param like scanf() functions family does.
105 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
106 // This is always with with_commas=false
107 // Returns number of scanned values
108 // (like sscanf() does)
109 // NOTE: unlike scanf family, this function only accepts
110 // *one* parameter !
111 int ScanParam(const wxString& par, const char *format, void *param) const;
112 int ScanParam(const wxString& par, const wchar_t *format, void *param) const;
113
114 // Returns string containing all params.
115 wxString GetAllParams() const;
116
117 // return true if there is matching ending tag
118 inline bool HasEnding() const {return m_hasEnding;}
119
120 // returns beginning position of _internal_ block of text
121 // See explanation (returned value is marked with *):
122 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
123 wxString::const_iterator GetBeginIter() const
124 { return m_Begin; }
125 // returns ending position of _internal_ block of text.
126 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
127 wxString::const_iterator GetEndIter1() const
128 { wxASSERT(m_hasEnding); return m_End1; }
129 // returns end position 2 :
130 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
131 wxString::const_iterator GetEndIter2() const
132 { wxASSERT(m_hasEnding); return m_End2; }
133
134 #if WXWIN_COMPATIBILITY_2_8
135 wxDEPRECATED( inline int GetBeginPos() const );
136 wxDEPRECATED( inline int GetEndPos1() const );
137 wxDEPRECATED( inline int GetEndPos2() const );
138 #endif // WXWIN_COMPATIBILITY_2_8
139
140 private:
141 wxString m_Name;
142 bool m_hasEnding;
143 wxString::const_iterator m_Begin, m_End1, m_End2;
144 wxArrayString m_ParamNames, m_ParamValues;
145 #if WXWIN_COMPATIBILITY_2_8
146 wxString::const_iterator m_sourceStart;
147 #endif
148
149 // DOM tree relations:
150 wxHtmlTag *m_Next;
151 wxHtmlTag *m_Prev;
152 wxHtmlTag *m_FirstChild, *m_LastChild;
153 wxHtmlTag *m_Parent;
154
155 DECLARE_NO_COPY_CLASS(wxHtmlTag)
156 };
157
158
159 #if WXWIN_COMPATIBILITY_2_8
160 inline int wxHtmlTag::GetBeginPos() const { return m_Begin - m_sourceStart; }
161 inline int wxHtmlTag::GetEndPos1() const { return m_End1 - m_sourceStart; }
162 inline int wxHtmlTag::GetEndPos2() const { return m_End2 - m_sourceStart; }
163 #endif // WXWIN_COMPATIBILITY_2_8
164
165
166
167
168 #endif // wxUSE_HTML
169
170 #endif // _WX_HTMLTAG_H_
171