2022-02-04 05:47:51 +01:00
|
|
|
#ifndef HTML_PARSER_H
|
|
|
|
#define HTML_PARSER_H
|
2021-11-18 00:59:13 +01:00
|
|
|
|
|
|
|
#include "core/containers/vector.h"
|
2021-11-18 12:03:43 +01:00
|
|
|
#include "core/string.h"
|
2021-11-18 00:59:13 +01:00
|
|
|
|
|
|
|
class HTMLParserAttribute {
|
|
|
|
public:
|
|
|
|
String attribute;
|
|
|
|
String data;
|
2021-11-18 12:03:43 +01:00
|
|
|
bool single;
|
|
|
|
|
2021-11-19 08:10:00 +01:00
|
|
|
bool match_attrib(const String &attrib);
|
|
|
|
bool match_data(const String &d);
|
|
|
|
bool match_data(const Vector<String> &d);
|
|
|
|
bool contains_data(const String &d);
|
|
|
|
|
2021-11-18 12:03:43 +01:00
|
|
|
String to_string();
|
|
|
|
void print();
|
2021-11-18 00:59:13 +01:00
|
|
|
|
|
|
|
HTMLParserAttribute();
|
|
|
|
virtual ~HTMLParserAttribute();
|
|
|
|
};
|
|
|
|
|
|
|
|
class HTMLParserTag {
|
|
|
|
public:
|
|
|
|
enum HTMLParserTagType {
|
|
|
|
HTML_PARSER_TAG_TYPE_NONE = 0,
|
|
|
|
HTML_PARSER_TAG_TYPE_OPENING_TAG,
|
|
|
|
HTML_PARSER_TAG_TYPE_CLOSING_TAG,
|
|
|
|
HTML_PARSER_TAG_TYPE_SELF_CLOSING_TAG,
|
|
|
|
HTML_PARSER_TAG_TYPE_COMMENT,
|
|
|
|
HTML_PARSER_TAG_TYPE_DOCTYPE,
|
|
|
|
HTML_PARSER_TAG_TYPE_CONTENT
|
|
|
|
};
|
|
|
|
|
|
|
|
int type;
|
|
|
|
|
|
|
|
String tag;
|
|
|
|
String data;
|
|
|
|
|
2021-11-18 12:03:43 +01:00
|
|
|
Vector<HTMLParserTag*> tags;
|
|
|
|
Vector<HTMLParserAttribute*> attributes;
|
2021-11-18 00:59:13 +01:00
|
|
|
|
2021-11-20 20:53:17 +01:00
|
|
|
HTMLParserTag *get_first(const String &t);
|
|
|
|
HTMLParserTag *get_first(const String &t, const String &attrib, const String &val);
|
|
|
|
|
|
|
|
String get_attribute_value(const String &attrib);
|
|
|
|
|
|
|
|
HTMLParserAttribute *get_attribute(const String &attrib);
|
|
|
|
bool has_attribute(const String &attrib);
|
|
|
|
|
|
|
|
HTMLParserAttribute *get_attribute(const String &attrib, const String &contains_val);
|
|
|
|
bool has_attribute(const String &attrib, const String &contains_val);
|
|
|
|
|
2021-11-18 00:59:13 +01:00
|
|
|
void process();
|
2021-11-18 12:03:43 +01:00
|
|
|
void parse_args(const String &args);
|
|
|
|
|
2021-11-18 12:21:47 +01:00
|
|
|
String to_string(const int level = 0);
|
2021-11-18 12:03:43 +01:00
|
|
|
void print();
|
2021-11-18 00:59:13 +01:00
|
|
|
|
|
|
|
HTMLParserTag();
|
|
|
|
virtual ~HTMLParserTag();
|
|
|
|
};
|
|
|
|
|
|
|
|
class HTMLParser {
|
|
|
|
public:
|
2021-11-18 12:07:28 +01:00
|
|
|
HTMLParserTag *root;
|
2021-11-18 00:59:13 +01:00
|
|
|
|
|
|
|
void parse(const String &data);
|
|
|
|
//void parse_tag(const String &data, const int index);
|
|
|
|
|
2021-11-18 12:03:43 +01:00
|
|
|
String to_string();
|
|
|
|
void print();
|
|
|
|
|
2021-11-18 00:59:13 +01:00
|
|
|
HTMLParser();
|
|
|
|
virtual ~HTMLParser();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|