#ifndef _HTMLTAG_H #define _HTMLTAG_H #include "extensions.h" #include "StringMap.h" #include "Streams.h" #include #include using namespace std; //---------------------------------------------------- HTML knowledge classes #define NORM false //used for not PI and not HEADING //processingInstruction #define PI true //jumpTag #define JUMP true #define PARSE false //inlineTag #define INLINE true #define BLOCK false //cssTag #define CSS true #define NCSS false //headingTag #define HEADING true //treat as unknown (do not include in maps) #define TREATASUNKNOWN true //using a Tag structure because of all the various useful properties we can give to a tag //that instruct the code how to handle them class HTMLTag: protected Character { unsigned int m_id; //sequential id of the HTMLTag (generated from m_ids.size()) static StringMapCI m_tags; //text lookup static vector m_ids; //id lookup const char *m_text; //e.g. "div" const bool m_processingInstruction; //PI or NORM (comments are ignored) const bool m_jumpTag; //JUMP or PARSE (jump over these blocks in the HTML) const bool m_inlineTag; //INLINE or BLOCK (affect the markup areas) const bool m_cssTag; //CSS or NCSS (include the tag in the CSS level information) const bool m_headingTag; const char *m_endtag; // If 0 then indicates that it can be generated from the tag name by this constructor. comment is n exception (-->) char *m_dynamicEndTag; //dynamic endtag if a 0 is sent through for the endtag (managed by the class) public: HTMLTag(const char *_text, bool _processingInstruction = NORM, bool _jumpTag = PARSE, bool _inlineTag = INLINE, bool _cssTag = CSS, bool _headingTag = NORM, const char *_endtag = 0, const bool treatAsUnknown = false); ~HTMLTag(); static HTMLTag //extra (included in maps) tag_comment, tag_DOCTYPE, tag_u, tag_s, tag_strike, //http://www.htmldog.com/reference/htmltags/ tag_a, tag_abbr, tag_acronym, tag_address, tag_area, tag_b, tag_base, tag_bdo, tag_big, tag_blink, tag_blockquote, tag_body, tag_br, tag_button, tag_caption, tag_cite, tag_code, tag_col, tag_colgroup, tag_dd, tag_del, tag_dfn, tag_div, tag_dl, tag_dt, tag_em, tag_fieldset, tag_font, tag_form, tag_h1, tag_h2, tag_h3, tag_h4, tag_h5, tag_h6, tag_head, tag_html, tag_hr, tag_i, tag_img, tag_input, tag_ins, tag_kbd, tag_label, tag_legend, tag_li, tag_link, tag_map, tag_meta, tag_noscript, tag_object, tag_ol, tag_optgroup, tag_option, tag_p, tag_param, tag_pre, tag_q, tag_samp, tag_script, tag_select, tag_small, tag_span, tag_strong, tag_style, tag_sub, tag_sup, tag_table, tag_tbody, tag_td, tag_textarea, tag_tfoot, tag_th, tag_thead, tag_title, tag_tr, tag_tt, tag_ul, tag_var; //special operators used primarily for comparing heading levels h1 > h6 const bool operator== (const HTMLTag *t) const {return this == t;} //compare address as these are singletons const bool operator!= (const HTMLTag *t) const {return !(this->operator==(t));} const bool operator> (const HTMLTag *t) const {return !t || strcmp(m_text, t->m_text) < 0;} //for example: tag_h1 > &tag_h6 is strcmp("h1", "h6") < 0 is true (1<6) const bool operator< (const HTMLTag *t) const {return !(this->operator>(t) || this->operator==(t));} const bool operator>= (const HTMLTag *t) const {return (this->operator>(t) || this->operator==(t));} const bool operator<= (const HTMLTag *t) const {return (this->operator<(t) || this->operator==(t));} //accessors unsigned int id() const {return m_id;} const char *text() const {return m_text;} const char *endtag() const {return (m_endtag ? m_endtag : m_dynamicEndTag);} const char processingInstruction() const {return m_processingInstruction;} const char jumpTag() const {return m_jumpTag;} const char inlineTag() const {return m_inlineTag;} const char cssTag() const {return m_cssTag;} const char headingTag() const {return m_headingTag;} //lookup static HTMLTag *gettag(const char *textstart); static HTMLTag *tag(unsigned int id) {return m_ids.at(id);} static HTMLTag *tag(const char *text); static HTMLTag *tag(const char *textstart, const char *textfinish); }; #endif