Removed unused bbcode stuff

This commit is contained in:
WolverinDEV 2020-01-24 02:42:13 +01:00
parent e4cdbf7385
commit 735e427376
2 changed files with 2 additions and 104 deletions

View File

@ -1,4 +1,3 @@
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
@ -7,61 +6,6 @@
using namespace std;
using namespace bbcode;
struct BBStack {
shared_ptr<BBEntry> head = make_shared<BBText>();
shared_ptr<BBEntry> tail = head;
string key;
string content;
};
shared_ptr<BBEntry> bbcode::parse(string message) {
string current_text;
string current_key;
deque<shared_ptr<BBStack>> stack;
stack.push_back(make_shared<BBStack>());
bool escaped = false;
bool key_begin = false;
bool key_end = false;
for(size_t i = 0; i < message.length(); i++) {
if(message[i] == '[' && (i == 0 || message[i - 1] != '\\')) {
if(!current_text.empty()) {
stack.back()->tail->next(make_shared<BBText>(current_text));
stack.back()->tail = stack.back()->tail->next();
}
if(i + 2 < message.length() && message[i + 1] == '/') { //Should be a key end
key_end = true;
i += 1;
continue;
} else {
key_begin = true;
cout << "Message: " << current_text << endl;
stack.push_back(make_shared<BBStack>());
continue;
}
} else if(message[i] == ']') {
if(key_begin) {
cout << "Got key begin '" << current_key << "'" << endl;
key_begin = false;
stack.back()->key = current_key;
current_key = "";
continue;
} else if(key_end) {
cout << "Got key end '" << current_key << "'" << endl;
key_end = false;
continue;
}
}
if(key_begin || key_end) current_key += message[i];
else current_text += message[i];
}
return stack.front()->head;
}
bool bbcode::sloppy::has_tag(std::string message, std::deque<std::string> tag) {
std::transform(message.begin(), message.end(), message.begin(), ::tolower);
for(auto& entry : tag)

View File

@ -3,55 +3,9 @@
#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 {
namespace bbcode::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"}); }
}
}
}