pandemonium_engine/modules/web/html/bbcode_parser.h

168 lines
5.4 KiB
C++
Raw Normal View History

#ifndef BBCODE_PARSER_H
#define BBCODE_PARSER_H
2023-12-18 00:25:33 +01:00
/*************************************************************************/
/* bbcode_parser.h */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/containers/vector.h"
2023-12-18 00:25:33 +01:00
#include "core/string/ustring.h"
#include "core/object/reference.h"
class BBCodeParserAttribute : public Reference {
GDCLASS(BBCodeParserAttribute, Reference);
public:
2022-07-19 19:20:34 +02:00
String get_attribute();
void set_attribute(const String &val);
String get_data();
void set_data(const String &val);
bool get_single();
void set_single(const bool &val);
bool match_attrib(const String &attrib);
bool match_data(const String &d);
2022-07-19 20:28:26 +02:00
bool match_all_data(const Vector<String> &d);
bool match_all_data_bind(const PoolStringArray &d);
bool contains_data(const String &d);
String convert_to_string() const;
void print() const;
BBCodeParserAttribute();
virtual ~BBCodeParserAttribute();
2022-07-19 19:20:34 +02:00
protected:
2022-07-19 20:28:26 +02:00
static void _bind_methods();
2022-07-19 19:20:34 +02:00
String _attribute;
String _data;
bool _single;
};
class BBCodeParserTag : public Reference {
GDCLASS(BBCodeParserTag, Reference);
public:
enum BBCodeParserTagType {
BBCODE_PARSER_TAG_TYPE_NONE = 0,
BBCODE_PARSER_TAG_TYPE_OPENING_TAG,
BBCODE_PARSER_TAG_TYPE_CLOSING_TAG,
BBCODE_PARSER_TAG_TYPE_SELF_CLOSING_TAG,
BBCODE_PARSER_TAG_TYPE_CONTENT
};
2022-07-19 19:20:34 +02:00
int get_type();
void set_type(const int &val);
String get_tag();
void set_tag(const String &val);
String get_data();
void set_data(const String &val);
void add_child_tag(const Ref<BBCodeParserTag> &tag);
void remote_child_tag(const int index);
Ref<BBCodeParserTag> get_child_tag(const int index);
int get_child_tag_count() const;
void clear_child_tags();
2022-07-19 19:20:34 +02:00
Vector<Variant> get_child_tags();
void set_child_tags(const Vector<Variant> &val);
2022-07-19 19:20:34 +02:00
void add_child_attribute(const Ref<BBCodeParserAttribute> &tag);
void remote_child_attribute(const int index);
Ref<BBCodeParserAttribute> get_child_attribute(const int index);
int get_child_attribute_count() const;
void clear_child_attributes();
Vector<Variant> get_attributes();
void set_attributes(const Vector<Variant> &val);
Ref<BBCodeParserTag> get_first(const String &t);
2022-07-19 20:28:26 +02:00
Ref<BBCodeParserTag> get_firstc(const String &t, const String &attrib, const String &val);
String get_attribute_value(const String &attrib);
Ref<BBCodeParserAttribute> get_attribute(const String &attrib);
bool has_attribute(const String &attrib);
2022-07-19 20:28:26 +02:00
Ref<BBCodeParserAttribute> get_attributec(const String &attrib, const String &contains_val);
bool has_attributec(const String &attrib, const String &contains_val);
void process();
void parse_args(const String &args);
String convert_to_string(const int level = 0) const;
void print() const;
BBCodeParserTag();
virtual ~BBCodeParserTag();
2022-07-19 19:20:34 +02:00
protected:
2022-07-19 20:28:26 +02:00
static void _bind_methods();
2022-07-19 19:20:34 +02:00
int _type;
String _tag;
String _data;
Vector<Ref<BBCodeParserTag>> _tags;
Vector<Ref<BBCodeParserAttribute>> _attributes;
};
class BBCodeParser : public Reference {
GDCLASS(BBCodeParser, Reference);
public:
2022-07-19 19:20:34 +02:00
Ref<BBCodeParserTag> get_root();
void parse(const String &data);
//void parse_tag(const String &data, const int index);
String convert_to_string() const;
void print() const;
BBCodeParser();
virtual ~BBCodeParser();
2022-07-19 19:20:34 +02:00
protected:
2022-07-19 20:28:26 +02:00
static void _bind_methods();
2022-07-19 19:20:34 +02:00
Ref<BBCodeParserTag> _root;
};
2022-07-19 20:28:26 +02:00
VARIANT_ENUM_CAST(BBCodeParserTag::BBCodeParserTagType);
#endif