TeaSpeakLibrary/src/bbcode/bbcodes.h

57 lines
1.6 KiB
C++

#pragma once
#include <deque>
#include <memory>
namespace bbcode {
enum BBType {
TEXT,
URL,
IMG,
LIST,
UNKNOWN
};
class BBEntry {
public:
virtual ~BBEntry() = default;
virtual BBType type() const = 0;
virtual std::string build() const = 0;
inline std::shared_ptr<BBEntry> next() const { return this->_next; }
inline std::shared_ptr<BBEntry> previus() const { return this->_previus; }
inline std::shared_ptr<BBEntry> parent() const { return this->_parent.lock(); }
inline void next(std::shared_ptr<BBEntry> next) { this->_next = std::move(next); }
inline void previus(std::shared_ptr<BBEntry> previus) { this->_previus = std::move(previus); }
inline void parent(std::shared_ptr<BBEntry> parent) { this->_parent = std::move(parent); }
protected:
std::weak_ptr<BBEntry> _parent;
std::shared_ptr<BBEntry> _previus;
std::shared_ptr<BBEntry> _next;
};
class BBText : public BBEntry {
public:
BBText(const std::string& text = "") { this->_text = text; }
inline std::string text() const { return this->_text; }
inline void text(const std::string& text) { this->_text = text; }
BBType type() const override { return BBType::TEXT; }
std::string build() const override { return _text; }
private:
std::string _text;
};
extern std::shared_ptr<BBEntry> parse(std::string);
namespace sloppy {
extern bool has_tag(std::string message, std::deque<std::string> tag);
inline bool has_url(const std::string& message) { return has_tag(message, {"url"}); }
inline bool has_image(const std::string& message) { return has_tag(message, {"img"}); }
}
}