Rename the different classes. I felt it was too verbose.

This commit is contained in:
Jacob 2024-05-12 20:18:06 +02:00
parent 8f3ba89445
commit 35a15651ca
5 changed files with 491 additions and 477 deletions

View file

@ -11,13 +11,13 @@
#include <docpp/docpp.hpp> #include <docpp/docpp.hpp>
int main() { int main() {
docpp::HTML::HTMLSection html(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section html(docpp::HTML::SECTION_HTML, {});
html.push_back({"title", {}, "Google"}); html.push_back({"title", {}, "Google"});
docpp::CSS::CSSStylesheet sheet{}; docpp::CSS::Stylesheet sheet{};
sheet.push_back(docpp::CSS::CSSElement( sheet.push_back(docpp::CSS::Element(
".center", { ".center", {
{"display", "flex"}, {"display", "flex"},
{"flex-wrap", "wrap"}, {"flex-wrap", "wrap"},
@ -29,7 +29,7 @@ int main() {
} }
)); ));
sheet.push_back(docpp::CSS::CSSElement( sheet.push_back(docpp::CSS::Element(
"input[type=text], select", { "input[type=text], select", {
{"width", "50vw"}, {"width", "50vw"},
} }
@ -37,27 +37,27 @@ int main() {
html.push_back({"style", {}, sheet.get(docpp::CSS::FORMATTING_PRETTY)}); html.push_back({"style", {}, sheet.get(docpp::CSS::FORMATTING_PRETTY)});
docpp::HTML::HTMLSection div{docpp::HTML::SECTION_DIV, {docpp::HTML::HTMLProperty("class", "center")}}; docpp::HTML::Section div{docpp::HTML::SECTION_DIV, {docpp::HTML::Property("class", "center")}};
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "blue")}, "G"}); div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "G"});
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "red")}, "o"}); div.push_back({"font", {docpp::HTML::Property("color", "red")}, "o"});
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "yellow")}, "o"}); div.push_back({"font", {docpp::HTML::Property("color", "yellow")}, "o"});
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "blue")}, "g"}); div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "g"});
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "green")}, "l"}); div.push_back({"font", {docpp::HTML::Property("color", "green")}, "l"});
div.push_back({"font", {docpp::HTML::HTMLProperty("color", "red")}, "e"}); div.push_back({"font", {docpp::HTML::Property("color", "red")}, "e"});
html.push_back(div); html.push_back(div);
docpp::HTML::HTMLSection div2{docpp::HTML::SECTION_DIV, {docpp::HTML::HTMLProperty("align", "center")}}; docpp::HTML::Section div2{docpp::HTML::SECTION_DIV, {docpp::HTML::Property("align", "center")}};
docpp::HTML::HTMLSection form{"form", {{docpp::HTML::HTMLProperty("action", "https://google.com/search"), docpp::HTML::HTMLProperty("method", "get")}}}; docpp::HTML::Section form{"form", {{docpp::HTML::Property("action", "https://google.com/search"), docpp::HTML::Property("method", "get")}}};
form.push_back({"input", docpp::HTML::HTMLProperties({docpp::HTML::HTMLProperty("type", "text"), docpp::HTML::HTMLProperty("name", "q")}), "", docpp::HTML::TYPE_SELF_CLOSING}); form.push_back({"input", docpp::HTML::Properties({docpp::HTML::Property("type", "text"), docpp::HTML::Property("name", "q")}), "", docpp::HTML::TYPE_SELF_CLOSING});
form.push_back({"input", docpp::HTML::HTMLProperties({docpp::HTML::HTMLProperty("type", "submit"), docpp::HTML::HTMLProperty("value", "Search!")}), "", docpp::HTML::TYPE_SELF_CLOSING}); form.push_back({"input", docpp::HTML::Properties({docpp::HTML::Property("type", "submit"), docpp::HTML::Property("value", "Search!")}), "", docpp::HTML::TYPE_SELF_CLOSING});
div2.push_back(form); div2.push_back(form);
html.push_back(div2); html.push_back(div2);
docpp::HTML::HTMLDocument doc{html}; docpp::HTML::Document doc{html};
std::ofstream file("biteme.lol.html"); std::ofstream file("biteme.lol.html");

View file

@ -12,18 +12,18 @@
int main() { int main() {
/* This is your root document. It can hold *one* HTML section, and that section can hold any number of elements and/or sections. /* This is your root document. It can hold *one* HTML section, and that section can hold any number of elements and/or sections.
* By default, the root document will prepend a doctype declaration. If you don't want that (e.g., if you're writing XML), you can * By default, the root document will prepend a doctype declaration. If you don't want that (e.g., if you're writing XML), you can
* use docpp::HTML::HTMLDocument::setDocType() to set the doctype to your preferred value. * use docpp::HTML::Document::setDocType() to set the doctype to your preferred value.
* *
* To get the document as an std::string object, call doc.get(). * To get the document as an std::string object, call doc.get().
*/ */
docpp::HTML::HTMLDocument doc{}; docpp::HTML::Document doc{};
/* This is an HTML section. It can hold any number of elements and/or sections. /* This is an HTML section. It can hold any number of elements and/or sections.
* The first argument is the type of section, and this can either be a predefined value (e.g., docpp::HTML::SECTION_HTML) or a * The first argument is the type of section, and this can either be a predefined value (e.g., docpp::HTML::SECTION_HTML) or a
* custom value in the form of an std::string object. * custom value in the form of an std::string object.
* *
* The second argument is an HTMLProperties object, which is a collection of HTMLProperty objects. Each property is a std::pair of an * The second argument is an HTMLProperties object, which is a collection of Property objects. Each property is a std::pair of an
* attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty HTMLElementAttributes object. * attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty ElementAttributes object.
* If you need to change the tag and/or attributes later, you can use the set() method. * If you need to change the tag and/or attributes later, you can use the set() method.
* *
* Note that it is very important that you do not append a section or element to a section until you have finished its construction, * Note that it is very important that you do not append a section or element to a section until you have finished its construction,
@ -32,16 +32,16 @@ int main() {
* *
* To get the section as an std::string object, call section.get(). * To get the section as an std::string object, call section.get().
*/ */
docpp::HTML::HTMLSection htmlSection(docpp::HTML::SECTION_HTML, {}); // <html></html> docpp::HTML::Section htmlSection(docpp::HTML::SECTION_HTML, {}); // <html></html>
docpp::HTML::HTMLSection headSection(docpp::HTML::SECTION_HEAD, {}); // <head></head> docpp::HTML::Section headSection(docpp::HTML::SECTION_HEAD, {}); // <head></head>
docpp::HTML::HTMLSection bodySection(docpp::HTML::SECTION_BODY, {}); // <body></body> docpp::HTML::Section bodySection(docpp::HTML::SECTION_BODY, {}); // <body></body>
docpp::HTML::HTMLSection footerSection(docpp::HTML::SECTION_FOOTER, {}); // <footer></footer> docpp::HTML::Section footerSection(docpp::HTML::SECTION_FOOTER, {}); // <footer></footer>
/* This is an HTML element. Unlike a section, an element cannot hold any other elements or sections, rather it holds text and/or attributes. /* This is an HTML element. Unlike a section, an element cannot hold any other elements or sections, rather it holds text and/or attributes.
* The first argument is the type of element, and this should simply be the tag name (e.g., "p", "h1", "a", etc.). * The first argument is the type of element, and this should simply be the tag name (e.g., "p", "h1", "a", etc.).
* *
* The second argument is an HTMLProperties object, which is a collection of HTMLProperty objects. Each property is a std::pair of an * The second argument is an HTMLProperties object, which is a collection of Property objects. Each property is a std::pair of an
* attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty HTMLElementAttributes object. * attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty ElementAttributes object.
* If you need to change the element's tag, attributes, type or text later, you can use the set() method. * If you need to change the element's tag, attributes, type or text later, you can use the set() method.
* *
* The third argument is the text content of the element. If you don't want to specify any text, you can pass an empty std::string object. * The third argument is the text content of the element. If you don't want to specify any text, you can pass an empty std::string object.
@ -57,45 +57,45 @@ int main() {
* *
* To get the element as an std::string object, call element.get(). * To get the element as an std::string object, call element.get().
*/ */
docpp::HTML::HTMLElement titleElement("title", {}, "Hello world document"); // <title>Hello world document</title> docpp::HTML::Element titleElement("title", {}, "Hello world document"); // <title>Hello world document</title>
/* Add the title and meta elements to the head section. */ /* Add the title and meta elements to the head section. */
headSection.push_back(titleElement); headSection.push_back(titleElement);
headSection.push_back(docpp::HTML::HTMLElement("meta", {{docpp::HTML::HTMLProperty("name", "description"), docpp::HTML::HTMLProperty("content", "Hello world document description!")}}, "", docpp::HTML::TYPE_NON_CLOSED)); headSection.push_back(docpp::HTML::Element("meta", {{docpp::HTML::Property("name", "description"), docpp::HTML::Property("content", "Hello world document description!")}}, "", docpp::HTML::TYPE_NON_CLOSED));
/* This is a CSS document. It is essentially the CSS equivalent of an HTML section. /* This is a CSS document. It is essentially the CSS equivalent of an HTML section.
* It is essentially a collection of CSSElement objects, which is a collection of CSSProperty objects. * It is essentially a collection of Element objects, which is a collection of Property objects.
* *
* In other words, a CSS document is a collection of CSS elements, which are collections of CSS properties. * In other words, a CSS document is a collection of CSS elements, which are collections of CSS properties.
*/ */
docpp::CSS::CSSStylesheet stylesheet{}; docpp::CSS::Stylesheet stylesheet{};
/* This is a CSS element. It is essentially a collection of CSS properties. /* This is a CSS element. It is essentially a collection of CSS properties.
* The first argument is the type of element, and this should simply be the tag name (e.g., "body", "p", "h1", etc.). * The first argument is the type of element, and this should simply be the tag name (e.g., "body", "p", "h1", etc.).
* *
* The second argument is a CSSProperties object, which is a collection of CSSProperty objects. Each property is a std::pair of a * The second argument is a CSSProperties object, which is a collection of Property objects. Each property is a std::pair of a
* property name and a property value. If you don't want to specify any properties, you can pass an empty CSSProperties object, but... of course, that's not very useful. * property name and a property value. If you don't want to specify any properties, you can pass an empty CSSProperties object, but... of course, that's not very useful.
* *
* To get the element as an std::string object, call element.get(). * To get the element as an std::string object, call element.get().
*/ */
docpp::CSS::CSSElement bodyStyling("body", {{docpp::CSS::CSSProperty("background-color", "black"), docpp::CSS::CSSProperty("color", "white")}}); // body { background-color: black; color: white; } docpp::CSS::Element bodyStyling("body", {{docpp::CSS::Property("background-color", "black"), docpp::CSS::Property("color", "white")}}); // body { background-color: black; color: white; }
/* Now, let's add the body style to the stylesheet. */ /* Now, let's add the body style to the stylesheet. */
stylesheet.push_back(bodyStyling); stylesheet.push_back(bodyStyling);
/* To get the stylesheet as an std::string object, call stylesheet.get(). It can then be used in an HTMLElement object. */ /* To get the stylesheet as an std::string object, call stylesheet.get(). It can then be used in an Element object. */
const std::string& css = stylesheet.get(docpp::CSS::FORMATTING_PRETTY); // body { background-color: black; color: white; } const std::string& css = stylesheet.get(docpp::CSS::FORMATTING_PRETTY); // body { background-color: black; color: white; }
headSection.push_back(docpp::HTML::HTMLElement("style", {}, css)); // <style>body { background-color: black; color: white; }</style> headSection.push_back(docpp::HTML::Element("style", {}, css)); // <style>body { background-color: black; color: white; }</style>
/* Add a paragraph element to the footer section. */ /* Add a paragraph element to the footer section. */
footerSection.push_back(docpp::HTML::HTMLElement("p", {}, "This is the footer.")); // <p>This is the footer.</p> footerSection.push_back(docpp::HTML::Element("p", {}, "This is the footer.")); // <p>This is the footer.</p>
docpp::HTML::HTMLSection divSection(docpp::HTML::SECTION_DIV, {{docpp::HTML::HTMLProperty("id", "main")}}); // <div id="main"></div> docpp::HTML::Section divSection(docpp::HTML::SECTION_DIV, {{docpp::HTML::Property("id", "main")}}); // <div id="main"></div>
/* Add a header element and a paragraph element to the div section. */ /* Add a header element and a paragraph element to the div section. */
divSection.push_back(docpp::HTML::HTMLElement("h1", {}, "Hello world!")); // <h1>Hello world!</h1> divSection.push_back(docpp::HTML::Element("h1", {}, "Hello world!")); // <h1>Hello world!</h1>
divSection.push_back(docpp::HTML::HTMLElement("p", {}, "This is a paragraph.")); // <p>This is a paragraph.</p> divSection.push_back(docpp::HTML::Element("p", {}, "This is a paragraph.")); // <p>This is a paragraph.</p>
/* Add the div section to the body section. */ /* Add the div section to the body section. */
bodySection.push_back(divSection); bodySection.push_back(divSection);

View file

@ -74,7 +74,7 @@ namespace docpp {
/** /**
* @brief A class to represent an HTML property * @brief A class to represent an HTML property
*/ */
class HTMLProperty { class Property {
private: private:
std::pair<std::string, std::string> property{}; std::pair<std::string, std::string> property{};
protected: protected:
@ -85,17 +85,17 @@ namespace docpp {
static const int npos = -1; static const int npos = -1;
/** /**
* @brief Construct a new HTMLProperty object * @brief Construct a new Property object
* @param key The key of the property * @param key The key of the property
* @param value The value of the property * @param value The value of the property
*/ */
HTMLProperty(const std::string& key, const std::string& value); Property(const std::string& key, const std::string& value);
/** /**
* @brief Construct a new HTMLProperty object * @brief Construct a new Property object
* @param property The property to set * @param property The property to set
*/ */
HTMLProperty(const std::pair<std::string, std::string>& property); Property(const std::pair<std::string, std::string>& property);
HTMLProperty() = default; Property() = default;
/** /**
* @brief Get the key of the property * @brief Get the key of the property
@ -129,18 +129,20 @@ namespace docpp {
void set(const std::pair<std::string, std::string>& property); void set(const std::pair<std::string, std::string>& property);
}; };
using HTMLProperty = Property;
/** /**
* @brief A class to represent the properties of an HTML element * @brief A class to represent the properties of an HTML element
*/ */
class HTMLProperties { class Properties {
private: private:
std::vector<HTMLProperty> properties{}; std::vector<Property> properties{};
protected: protected:
public: public:
using iterator = std::vector<HTMLProperty>::iterator; using iterator = std::vector<Property>::iterator;
using const_iterator = std::vector<HTMLProperty>::const_iterator; using const_iterator = std::vector<Property>::const_iterator;
using reverse_iterator = std::vector<HTMLProperty>::reverse_iterator; using reverse_iterator = std::vector<Property>::reverse_iterator;
using const_reverse_iterator = std::vector<HTMLProperty>::const_reverse_iterator; using const_reverse_iterator = std::vector<Property>::const_reverse_iterator;
/** /**
* @brief Return an iterator to the beginning. * @brief Return an iterator to the beginning.
@ -190,26 +192,26 @@ namespace docpp {
/** /**
* @brief Get the properties of the element * @brief Get the properties of the element
* @return std::vector<HTMLProperty> The properties of the element * @return std::vector<Property> The properties of the element
*/ */
std::vector<HTMLProperty> getProperties() const; std::vector<Property> getProperties() const;
/** /**
* @brief Set the properties of the element * @brief Set the properties of the element
* @param properties The properties to set * @param properties The properties to set
*/ */
void set(const std::vector<HTMLProperty>& properties); void set(const std::vector<Property>& properties);
/** /**
* @brief Get the property at an index * @brief Get the property at an index
* @param index The index of the property * @param index The index of the property
* @return HTMLProperty The property at the index * @return Property The property at the index
*/ */
HTMLProperty at(const int index) const; Property at(const int index) const;
/** /**
* @brief Insert a property into the element * @brief Insert a property into the element
* @param index The index to insert the property * @param index The index to insert the property
* @param property The property to insert * @param property The property to insert
*/ */
void insert(const int index, const HTMLProperty& property); void insert(const int index, const Property& property);
/** /**
* @brief Erase a property from the element * @brief Erase a property from the element
* @param index The index of the property to erase * @param index The index of the property to erase
@ -220,7 +222,7 @@ namespace docpp {
* @param property The property to find * @param property The property to find
* @return int The index of the property * @return int The index of the property
*/ */
int find(const HTMLProperty& property); int find(const Property& property);
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param str The property to find * @param str The property to find
@ -238,17 +240,17 @@ namespace docpp {
* @param property1 The first property * @param property1 The first property
* @param property2 The second property * @param property2 The second property
*/ */
void swap(const HTMLProperty& property1, const HTMLProperty& property2); void swap(const Property& property1, const Property& property2);
/** /**
* @brief Get the first property of the element * @brief Get the first property of the element
* @return HTMLProperty The first property of the element * @return Property The first property of the element
*/ */
HTMLProperty front() const; Property front() const;
/** /**
* @brief Get the last property of the element * @brief Get the last property of the element
* @return HTMLProperty The last property of the element * @return Property The last property of the element
*/ */
HTMLProperty back() const; Property back() const;
/** /**
* @brief Get the size of the element * @brief Get the size of the element
* @return int The size of the element * @return int The size of the element
@ -258,43 +260,43 @@ namespace docpp {
* @brief Prepend a property to the element * @brief Prepend a property to the element
* @param property The property to add * @param property The property to add
*/ */
void push_front(const HTMLProperty& property); void push_front(const Property& property);
/** /**
* @brief Append a property to the element * @brief Append a property to the element
* @param property The property to add * @param property The property to add
*/ */
void push_back(const HTMLProperty& property); void push_back(const Property& property);
/** /**
* @brief Construct a new HTMLProperties object * @brief Construct a new Properties object
* @param properties The properties to set * @param properties The properties to set
*/ */
HTMLProperties(const std::vector<HTMLProperty>& properties); Properties(const std::vector<Property>& properties);
/** /**
* @brief Construct a new HTMLProperties object * @brief Construct a new Properties object
* @param property The property to add * @param property The property to add
*/ */
HTMLProperties(const HTMLProperty& property); Properties(const Property& property);
/** /**
* @brief Construct a new HTMLProperties object * @brief Construct a new Properties object
*/ */
HTMLProperties() = default; Properties() = default;
HTMLProperties operator=(const HTMLProperties& properties); Properties operator=(const Properties& properties);
HTMLProperties operator=(const std::vector<HTMLProperty>& properties); Properties operator=(const std::vector<Property>& properties);
HTMLProperties operator=(const HTMLProperty& property); Properties operator=(const Property& property);
void operator+=(const HTMLProperty& property); void operator+=(const Property& property);
}; };
using HTMLElementProperties = HTMLProperties; using HTMLElementProperties = Properties;
/** /**
* @brief A class to represent an HTML element * @brief A class to represent an HTML element
*/ */
class HTMLElement { class Element {
private: private:
std::string tag{}; std::string tag{};
std::string data{}; std::string data{};
int type{TYPE_NON_SELF_CLOSING}; int type{TYPE_NON_SELF_CLOSING};
HTMLProperties properties{}; Properties properties{};
protected: protected:
public: public:
/** /**
@ -303,23 +305,23 @@ namespace docpp {
static const int npos = -1; static const int npos = -1;
/** /**
* @brief Construct a new HTMLElement object * @brief Construct a new Element object
* @param tag The tag of the element * @param tag The tag of the element
* @param properties The properties of the element * @param properties The properties of the element
* @param data The data of the element * @param data The data of the element
*/ */
HTMLElement(const std::string& tag, const HTMLProperties& properties = {}, const std::string& data = {}, const int type = TYPE_NON_SELF_CLOSING); Element(const std::string& tag, const Properties& properties = {}, const std::string& data = {}, const int type = TYPE_NON_SELF_CLOSING);
/** /**
* @brief Construct a new HTMLElement object * @brief Construct a new Element object
*/ */
HTMLElement() = default; Element() = default;
/** /**
* @brief Set the tag, id, and classes of the element * @brief Set the tag, id, and classes of the element
* @param tag The tag of the element * @param tag The tag of the element
* @param id The id of the element * @param id The id of the element
* @param classes The classes of the element * @param classes The classes of the element
*/ */
void set(const std::string& tag, const HTMLProperties& properties = {}, const std::string& data = {}, const int type = TYPE_NON_SELF_CLOSING); void set(const std::string& tag, const Properties& properties = {}, const std::string& data = {}, const int type = TYPE_NON_SELF_CLOSING);
/** /**
* @brief Get the element in the form of an HTML tag. * @brief Get the element in the form of an HTML tag.
@ -338,25 +340,27 @@ namespace docpp {
* @return std::string The data of the element * @return std::string The data of the element
*/ */
std::string getData() const; std::string getData() const;
HTMLElement operator=(const HTMLElement& element); Element operator=(const Element& element);
void operator+=(const std::string& data); void operator+=(const std::string& data);
}; };
using HTMLElement = Element;
/** /**
* @brief A class to represent an HTML section (head, body, etc.) * @brief A class to represent an HTML section (head, body, etc.)
*/ */
class HTMLSection { class Section {
private: private:
int index{}; int index{};
std::string tag{}; std::string tag{};
HTMLProperties properties{}; Properties properties{};
std::map<int, HTMLElement> elements{}; std::map<int, Element> elements{};
std::unordered_map<int, HTMLSection> sections{}; std::unordered_map<int, Section> sections{};
protected: protected:
public: public:
/** /**
* @brief A class to represent an iterator for the HTMLSection class * @brief A class to represent an iterator for the Section class
*/ */
template <typename T> template <typename T>
class sect_iterator { class sect_iterator {
@ -365,15 +369,15 @@ namespace docpp {
public: public:
sect_iterator(const T& element) : element(element) {} sect_iterator(const T& element) : element(element) {}
sect_iterator operator++() { return ++element; } sect_iterator operator++() { return ++element; }
HTMLElement operator*() { return element->second; } Element operator*() { return element->second; }
bool operator==(const sect_iterator& other) { return element == other.element; } bool operator==(const sect_iterator& other) { return element == other.element; }
bool operator!=(const sect_iterator& other) { return element != other.element; } bool operator!=(const sect_iterator& other) { return element != other.element; }
}; };
using iterator = sect_iterator<std::map<int, HTMLElement>::iterator>; using iterator = sect_iterator<std::map<int, Element>::iterator>;
using const_iterator = sect_iterator<std::map<int, HTMLElement>::const_iterator>; using const_iterator = sect_iterator<std::map<int, Element>::const_iterator>;
using reverse_iterator = sect_iterator<std::map<int, HTMLElement>::reverse_iterator>; using reverse_iterator = sect_iterator<std::map<int, Element>::reverse_iterator>;
using const_reverse_iterator = sect_iterator<std::map<int, HTMLElement>::const_reverse_iterator>; using const_reverse_iterator = sect_iterator<std::map<int, Element>::const_reverse_iterator>;
iterator begin() { return iterator(elements.begin()); } iterator begin() { return iterator(elements.begin()); }
iterator end() { return iterator(elements.end()); } iterator end() { return iterator(elements.end()); }
@ -393,34 +397,34 @@ namespace docpp {
* @brief Prepend an element to the section * @brief Prepend an element to the section
* @param element The element to add * @param element The element to add
*/ */
void push_front(const HTMLElement& element); void push_front(const Element& element);
/** /**
* @brief Prepend a section to the section * @brief Prepend a section to the section
* @param section The section to add * @param section The section to add
*/ */
void push_front(const HTMLSection& section); void push_front(const Section& section);
/** /**
* @brief Append an element to the section * @brief Append an element to the section
* @param element The element to add * @param element The element to add
*/ */
void push_back(const HTMLElement& element); void push_back(const Element& element);
/** /**
* @brief Append a section to the section * @brief Append a section to the section
* @param section The section to add * @param section The section to add
*/ */
void push_back(const HTMLSection& section); void push_back(const Section& section);
/** /**
* @brief Get the element at an index. To get a section, use at_section() * @brief Get the element at an index. To get a section, use at_section()
* @param index The index of the element * @param index The index of the element
* @return HTMLElement The element at the index * @return Element The element at the index
*/ */
HTMLElement at(const int index) const; Element at(const int index) const;
/** /**
* @brief Get the section at an index. To get an element, use at() * @brief Get the section at an index. To get an element, use at()
* @param index The index of the section * @param index The index of the section
* @return HTMLSection The section at the index * @return Section The section at the index
*/ */
HTMLSection at_section(const int index) const; Section at_section(const int index) const;
/** /**
* @brief Erase an element from the section. Note that this will NOT change the size/index. * @brief Erase an element from the section. Note that this will NOT change the size/index.
* @param index The index of the element to erase * @param index The index of the element to erase
@ -430,24 +434,24 @@ namespace docpp {
* @brief Erase a section from the section, by reading from a section. The section will be erased if it's identical to section. Note that this will NOT change the size/index. * @brief Erase a section from the section, by reading from a section. The section will be erased if it's identical to section. Note that this will NOT change the size/index.
* @param section The section to erase * @param section The section to erase
*/ */
void erase(const HTMLSection& section); void erase(const Section& section);
/** /**
* @brief Erase an element from the section, by reading from an element. The element will be erased if it's identical to element. Note that this will NOT change the size/index. * @brief Erase an element from the section, by reading from an element. The element will be erased if it's identical to element. Note that this will NOT change the size/index.
* @param element The element to erase * @param element The element to erase
*/ */
void erase(const HTMLElement& element); void erase(const Element& element);
/** /**
* @brief Find an element in the section * @brief Find an element in the section
* @param element The element to find * @param element The element to find
* @return int The index of the element * @return int The index of the element
*/ */
int find(const HTMLElement& element); int find(const Element& element);
/** /**
* @brief Find a section in the section * @brief Find a section in the section
* @param section The section to find * @param section The section to find
* @return int The index of the section * @return int The index of the section
*/ */
int find(const HTMLSection& section); int find(const Section& section);
/** /**
* @brief Find an element or section in the section * @brief Find an element or section in the section
* @param str The element or section to find * @param str The element or section to find
@ -459,33 +463,33 @@ namespace docpp {
* @param index The index to insert the element * @param index The index to insert the element
* @param element The element to insert * @param element The element to insert
*/ */
void insert(const int index, const HTMLElement& element); void insert(const int index, const Element& element);
/** /**
* @brief Insert a section into the section * @brief Insert a section into the section
* @param index The index to insert the section * @param index The index to insert the section
* @param section The section to insert * @param section The section to insert
*/ */
void insert(const int index, const HTMLSection& section); void insert(const int index, const Section& section);
/** /**
* @brief Get the first element of the section * @brief Get the first element of the section
* @return HTMLElement The first element of the section * @return Element The first element of the section
*/ */
HTMLElement front() const; Element front() const;
/** /**
* @brief Get the last element of the section * @brief Get the last element of the section
* @return HTMLElement The last element of the section * @return Element The last element of the section
*/ */
HTMLElement back() const; Element back() const;
/** /**
* @brief Get the first section of the section * @brief Get the first section of the section
* @return HTMLSection The first section of the section * @return Section The first section of the section
*/ */
HTMLSection front_section() const; Section front_section() const;
/** /**
* @brief Get the last section of the section * @brief Get the last section of the section
* @return HTMLSection The last section of the section * @return Section The last section of the section
*/ */
HTMLSection back_section() const; Section back_section() const;
/** /**
* @brief Get the size of the section * @brief Get the size of the section
* @return int The size of the section * @return int The size of the section
@ -493,35 +497,35 @@ namespace docpp {
int size() const; int size() const;
/** /**
* @brief Construct a new HTMLSection object * @brief Construct a new Section object
* @param tag The tag of the section * @param tag The tag of the section
* @param properties The properties of the section * @param properties The properties of the section
*/ */
HTMLSection(const std::string& tag, const HTMLProperties& properties = {}); Section(const std::string& tag, const Properties& properties = {});
/** /**
* @brief Construct a new HTMLSection object * @brief Construct a new Section object
* @param tag The tag of the section * @param tag The tag of the section
* @param properties The properties of the section * @param properties The properties of the section
*/ */
HTMLSection(const int tag, const HTMLProperties& properties = {}); Section(const int tag, const Properties& properties = {});
/** /**
* @brief Construct a new HTMLSection object * @brief Construct a new Section object
*/ */
HTMLSection() = default; Section() = default;
/** /**
* @brief Set the tag, id, and classes of the section * @brief Set the tag, id, and classes of the section
* @param tag The tag of the section * @param tag The tag of the section
* @param id The id of the section * @param id The id of the section
* @param classes The classes of the section * @param classes The classes of the section
*/ */
void set(const std::string& tag, const HTMLProperties& properties = {}); void set(const std::string& tag, const Properties& properties = {});
/** /**
* @brief Set the tag, id, and classes of the section * @brief Set the tag, id, and classes of the section
* @param tag The tag of the section * @param tag The tag of the section
* @param id The id of the section * @param id The id of the section
* @param classes The classes of the section * @param classes The classes of the section
*/ */
void set(const int tag, const HTMLProperties& properties = {}); void set(const int tag, const Properties& properties = {});
/** /**
* @brief Swap two elements in the section * @brief Swap two elements in the section
* @param index1 The index of the first element * @param index1 The index of the first element
@ -533,23 +537,23 @@ namespace docpp {
* @param element1 The first element * @param element1 The first element
* @param element2 The second element * @param element2 The second element
*/ */
void swap(const HTMLElement& element1, const HTMLElement& element2); void swap(const Element& element1, const Element& element2);
/** /**
* @brief Swap two sections in the section * @brief Swap two sections in the section
* @param index1 The index of the first section * @param index1 The index of the first section
* @param index2 The index of the second section * @param index2 The index of the second section
*/ */
void swap(const HTMLSection& section1, const HTMLSection& section2); void swap(const Section& section1, const Section& section2);
/** /**
* @brief Get the elements of the section * @brief Get the elements of the section
* @return std::vector<HTMLElement> The elements of the section * @return std::vector<Element> The elements of the section
*/ */
std::vector<HTMLElement> getHTMLElements() const; std::vector<Element> getElements() const;
/** /**
* @brief Get the sections of the section * @brief Get the sections of the section
* @return std::vector<HTMLSection> The sections of the section * @return std::vector<Section> The sections of the section
*/ */
std::vector<HTMLSection> getHTMLSections() const; std::vector<Section> getSections() const;
/** /**
* @brief Dump the entire section. * @brief Dump the entire section.
@ -557,19 +561,21 @@ namespace docpp {
*/ */
std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const;
HTMLSection operator=(const HTMLSection& section); Section operator=(const Section& section);
void operator+=(const HTMLElement& element); void operator+=(const Element& element);
void operator+=(const HTMLSection& section); void operator+=(const Section& section);
HTMLElement operator[](const int& index) const; Element operator[](const int& index) const;
}; };
using HTMLSection = Section;
/** /**
* @brief A class to represent an HTML document * @brief A class to represent an HTML document
*/ */
class HTMLDocument { class Document {
private: private:
std::string doctype{"<!DOCTYPE html>"}; std::string doctype{"<!DOCTYPE html>"};
HTMLSection document{}; Section document{};
protected: protected:
public: public:
/** /**
@ -586,9 +592,9 @@ namespace docpp {
/** /**
* @brief Get the section * @brief Get the section
* @return HTMLSection The section * @return Section The section
*/ */
HTMLSection& getSection(); Section& getSection();
/** /**
* @brief Get the doctype of the document * @brief Get the doctype of the document
@ -600,25 +606,27 @@ namespace docpp {
* @brief Set the document * @brief Set the document
* @param document The document to set * @param document The document to set
*/ */
void set(const HTMLSection& document); void set(const Section& document);
/** /**
* @brief Set the doctype of the document * @brief Set the doctype of the document
* @param doctype The doctype to set * @param doctype The doctype to set
*/ */
void setDoctype(const std::string& doctype); void setDoctype(const std::string& doctype);
/** /**
* @brief Construct a new HTMLDocument object * @brief Construct a new Document object
*/ */
HTMLDocument() = default; Document() = default;
/** /**
* @brief Construct a new HTMLDocument object * @brief Construct a new Document object
* @param document The document to set * @param document The document to set
*/ */
HTMLDocument(const HTMLSection& document, const std::string& doctype = "<!DOCTYPE html>"); Document(const Section& document, const std::string& doctype = "<!DOCTYPE html>");
HTMLDocument operator=(const HTMLDocument& document); Document operator=(const Document& document);
HTMLDocument operator=(const HTMLSection& section); Document operator=(const Section& section);
}; };
using HTMLDocument = Document;
} // namespace HTML } // namespace HTML
/** /**
@ -634,7 +642,7 @@ namespace docpp {
/** /**
* @brief A class to represent a CSS property * @brief A class to represent a CSS property
*/ */
class CSSProperty { class Property {
private: private:
std::pair<std::string, std::string> property{}; std::pair<std::string, std::string> property{};
protected: protected:
@ -645,17 +653,17 @@ namespace docpp {
static const int npos = -1; static const int npos = -1;
/** /**
* @brief Construct a new CSSProperty object * @brief Construct a new Property object
* @param key The key of the property * @param key The key of the property
* @param value The value of the property * @param value The value of the property
*/ */
CSSProperty(const std::string& key, const std::string& value); Property(const std::string& key, const std::string& value);
/** /**
* @brief Construct a new CSSProperty object * @brief Construct a new Property object
* @param property The property to set * @param property The property to set
*/ */
CSSProperty(const std::pair<std::string, std::string>& property); Property(const std::pair<std::string, std::string>& property);
CSSProperty() = default; Property() = default;
/** /**
* @brief Get the key of the property * @brief Get the key of the property
@ -694,19 +702,21 @@ namespace docpp {
*/ */
void set(const std::string& key, const std::string& value); void set(const std::string& key, const std::string& value);
CSSProperty operator=(const CSSProperty& property); Property operator=(const Property& property);
CSSProperty operator=(const std::pair<std::string, std::string>& property); Property operator=(const std::pair<std::string, std::string>& property);
}; };
class CSSElement { using CSSProperty = Property;
class Element {
private: private:
std::pair<std::string, std::vector<CSSProperty>> element{}; std::pair<std::string, std::vector<Property>> element{};
protected: protected:
public: public:
using iterator = std::vector<CSSProperty>::iterator; using iterator = std::vector<Property>::iterator;
using const_iterator = std::vector<CSSProperty>::const_iterator; using const_iterator = std::vector<Property>::const_iterator;
using reverse_iterator = std::vector<CSSProperty>::reverse_iterator; using reverse_iterator = std::vector<Property>::reverse_iterator;
using const_reverse_iterator = std::vector<CSSProperty>::const_reverse_iterator; using const_reverse_iterator = std::vector<Property>::const_reverse_iterator;
/** /**
* @brief Return an iterator to the beginning. * @brief Return an iterator to the beginning.
@ -755,34 +765,34 @@ namespace docpp {
static const int npos = -1; static const int npos = -1;
/** /**
* @brief Construct a new CSSElement object * @brief Construct a new Element object
* @param tag The tag of the element * @param tag The tag of the element
* @param properties The properties of the element * @param properties The properties of the element
*/ */
CSSElement(const std::string& tag, const std::vector<CSSProperty>& properties); Element(const std::string& tag, const std::vector<Property>& properties);
/** /**
* @brief Construct a new CSSElement object * @brief Construct a new Element object
* @param element The element to set * @param element The element to set
*/ */
CSSElement(const std::pair<std::string, std::vector<CSSProperty>>& element); Element(const std::pair<std::string, std::vector<Property>>& element);
CSSElement() = default; Element() = default;
/** /**
* @brief Prepend a property to the element * @brief Prepend a property to the element
* @param property The property to push * @param property The property to push
*/ */
void push_front(const CSSProperty& property); void push_front(const Property& property);
/** /**
* @brief Append a property to the element * @brief Append a property to the element
* @param property The property to push * @param property The property to push
*/ */
void push_back(const CSSProperty& property); void push_back(const Property& property);
/** /**
* @brief Insert a property into the element * @brief Insert a property into the element
* @param index The index to insert the property * @param index The index to insert the property
* @param property The property to insert * @param property The property to insert
*/ */
void insert(const int index, const CSSProperty& property); void insert(const int index, const Property& property);
/** /**
* @brief Erase a property from the element * @brief Erase a property from the element
* @param index The index of the property to erase * @param index The index of the property to erase
@ -793,13 +803,13 @@ namespace docpp {
* @param property The property to find * @param property The property to find
* @return int The index of the property * @return int The index of the property
*/ */
int find(const CSSProperty& property); int find(const Property& property);
/** /**
* @brief Get the property at an index * @brief Get the property at an index
* @param index The index of the property * @param index The index of the property
* @return CSSProperty The property at the index * @return Property The property at the index
*/ */
CSSProperty at(const int index) const; Property at(const int index) const;
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param str The property to find * @param str The property to find
@ -817,17 +827,17 @@ namespace docpp {
* @param property1 The first property * @param property1 The first property
* @param property2 The second property * @param property2 The second property
*/ */
void swap(const CSSProperty& property1, const CSSProperty& property2); void swap(const Property& property1, const Property& property2);
/** /**
* @brief Get the first property of the element * @brief Get the first property of the element
* @return CSSProperty The first property of the element * @return Property The first property of the element
*/ */
CSSProperty front() const; Property front() const;
/** /**
* @brief Get the last property of the element * @brief Get the last property of the element
* @return CSSProperty The last property of the element * @return Property The last property of the element
*/ */
CSSProperty back() const; Property back() const;
/** /**
* @brief Get the size of the element * @brief Get the size of the element
* @return int The size of the element * @return int The size of the element
@ -837,15 +847,15 @@ namespace docpp {
* @brief Set the properties of the element * @brief Set the properties of the element
* @param properties The properties to set * @param properties The properties to set
*/ */
void set(const std::string& tag, const std::vector<CSSProperty>& properties); void set(const std::string& tag, const std::vector<Property>& properties);
/** /**
* @brief Set the properties of the element * @brief Set the properties of the element
* @param element The element to set * @param element The element to set
*/ */
void set(const std::pair<std::string, std::vector<CSSProperty>>& element); void set(const std::pair<std::string, std::vector<Property>>& element);
/** /**
* @brief Get the element * @brief Get the element
* @return std::pair<std::string, std::vector<CSSProperty>> The element * @return std::pair<std::string, std::vector<Property>> The element
*/ */
std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const;
/** /**
@ -855,28 +865,30 @@ namespace docpp {
std::string getTag() const; std::string getTag() const;
/** /**
* @brief Get the properties of the element * @brief Get the properties of the element
* @return std::vector<CSSProperty> The properties of the element * @return std::vector<Property> The properties of the element
*/ */
std::vector<CSSProperty> getProperties() const; std::vector<Property> getProperties() const;
CSSElement operator=(const CSSElement& element); Element operator=(const Element& element);
CSSElement operator=(const std::pair<std::string, std::vector<CSSProperty>>& element); Element operator=(const std::pair<std::string, std::vector<Property>>& element);
void operator+=(const CSSProperty& property); void operator+=(const Property& property);
CSSProperty operator[](const int& index) const; Property operator[](const int& index) const;
}; };
using CSSElement = Element;
/** /**
* @brief A class to represent a CSS stylesheet * @brief A class to represent a CSS stylesheet
*/ */
class CSSStylesheet { class Stylesheet {
private: private:
std::vector<CSSElement> elements{}; std::vector<Element> elements{};
protected: protected:
public: public:
using iterator = std::vector<CSSElement>::iterator; using iterator = std::vector<Element>::iterator;
using const_iterator = std::vector<CSSElement>::const_iterator; using const_iterator = std::vector<Element>::const_iterator;
using reverse_iterator = std::vector<CSSElement>::reverse_iterator; using reverse_iterator = std::vector<Element>::reverse_iterator;
using const_reverse_iterator = std::vector<CSSElement>::const_reverse_iterator; using const_reverse_iterator = std::vector<Element>::const_reverse_iterator;
/** /**
* @brief Return an iterator to the beginning. * @brief Return an iterator to the beginning.
@ -925,28 +937,28 @@ namespace docpp {
static const int npos = -1; static const int npos = -1;
/** /**
* @brief Construct a new CSSStylesheet object * @brief Construct a new Stylesheet object
* @param elements The elements to set * @param elements The elements to set
*/ */
CSSStylesheet(const std::vector<CSSElement>& elements); Stylesheet(const std::vector<Element>& elements);
CSSStylesheet() = default; Stylesheet() = default;
/** /**
* @brief Prepend an element to the stylesheet * @brief Prepend an element to the stylesheet
* @param element The element to add * @param element The element to add
*/ */
void push_front(const CSSElement& element); void push_front(const Element& element);
/** /**
* @brief Append an element to the stylesheet * @brief Append an element to the stylesheet
* @param element The element to add * @param element The element to add
*/ */
void push_back(const CSSElement& element); void push_back(const Element& element);
/** /**
* @brief Insert an element into the stylesheet * @brief Insert an element into the stylesheet
* @param index The index to insert the element * @param index The index to insert the element
* @param element The element to insert * @param element The element to insert
*/ */
void insert(const int index, const CSSElement& element); void insert(const int index, const Element& element);
/** /**
* @brief Erase an element from the stylesheet. Note that this will NOT change the size/index. * @brief Erase an element from the stylesheet. Note that this will NOT change the size/index.
* @param index The index of the element to erase * @param index The index of the element to erase
@ -957,7 +969,7 @@ namespace docpp {
* @param element The element to find * @param element The element to find
* @return int The index of the element * @return int The index of the element
*/ */
int find(const CSSElement& element); int find(const Element& element);
/** /**
* @brief Find an element in the stylesheet * @brief Find an element in the stylesheet
* @param str The element to find, either the tag or the stylesheet itself * @param str The element to find, either the tag or the stylesheet itself
@ -967,9 +979,9 @@ namespace docpp {
/** /**
* @brief Get the element at an index * @brief Get the element at an index
* @param index The index of the element * @param index The index of the element
* @return CSSElement The element at the index * @return Element The element at the index
*/ */
CSSElement at(const int index) const; Element at(const int index) const;
/** /**
* @brief Get the size of the stylesheet * @brief Get the size of the stylesheet
* @return int The size of the stylesheet * @return int The size of the stylesheet
@ -977,14 +989,14 @@ namespace docpp {
int size() const; int size() const;
/** /**
* @brief Get the first element of the stylesheet * @brief Get the first element of the stylesheet
* @return CSSElement The first element of the stylesheet * @return Element The first element of the stylesheet
*/ */
CSSElement front() const; Element front() const;
/** /**
* @brief Get the last element of the stylesheet * @brief Get the last element of the stylesheet
* @return CSSElement The last element of the stylesheet * @return Element The last element of the stylesheet
*/ */
CSSElement back() const; Element back() const;
/** /**
* @brief Swap two elements in the stylesheet * @brief Swap two elements in the stylesheet
* @param index1 The index of the first element * @param index1 The index of the first element
@ -996,26 +1008,28 @@ namespace docpp {
* @param element1 The first element * @param element1 The first element
* @param element2 The second element * @param element2 The second element
*/ */
void swap(const CSSElement& element1, const CSSElement& element2); void swap(const Element& element1, const Element& element2);
/** /**
* @brief Set the elements of the stylesheet * @brief Set the elements of the stylesheet
* @param elements The elements to set * @param elements The elements to set
*/ */
void set(const std::vector<CSSElement>& elements); void set(const std::vector<Element>& elements);
/** /**
* @brief Get the elements of the stylesheet * @brief Get the elements of the stylesheet
* @return std::vector<CSSElement> The elements of the stylesheet * @return std::vector<Element> The elements of the stylesheet
*/ */
std::vector<CSSElement> getElements() const; std::vector<Element> getElements() const;
/** /**
* @brief Get the stylesheet * @brief Get the stylesheet
* @return std::string The stylesheet * @return std::string The stylesheet
*/ */
std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const;
CSSStylesheet operator=(const CSSStylesheet& stylesheet); Stylesheet operator=(const Stylesheet& stylesheet);
void operator+=(const CSSElement& element); void operator+=(const Element& element);
CSSElement operator[](const int& index) const; Element operator[](const int& index) const;
}; };
using CSSStylesheet = Stylesheet;
} }
} }

View file

@ -16,71 +16,71 @@
#include <string> #include <string>
#include <vector> #include <vector>
docpp::HTML::HTMLProperty::HTMLProperty(const std::string& key, const std::string& value) { docpp::HTML::Property::Property(const std::string& key, const std::string& value) {
this->setKey(key); this->setKey(key);
this->setValue(value); this->setValue(value);
} }
docpp::HTML::HTMLProperty::HTMLProperty(const std::pair<std::string, std::string>& property) { docpp::HTML::Property::Property(const std::pair<std::string, std::string>& property) {
this->set(property); this->set(property);
} }
std::string docpp::HTML::HTMLProperty::getKey() const { std::string docpp::HTML::Property::getKey() const {
return this->property.first; return this->property.first;
} }
std::string docpp::HTML::HTMLProperty::getValue() const { std::string docpp::HTML::Property::getValue() const {
return this->property.second; return this->property.second;
} }
std::pair<std::string, std::string> docpp::HTML::HTMLProperty::get() const { std::pair<std::string, std::string> docpp::HTML::Property::get() const {
return this->property; return this->property;
} }
void docpp::HTML::HTMLProperty::setKey(const std::string& key) { void docpp::HTML::Property::setKey(const std::string& key) {
this->property.first = key; this->property.first = key;
} }
void docpp::HTML::HTMLProperty::setValue(const std::string& value) { void docpp::HTML::Property::setValue(const std::string& value) {
this->property.second = value; this->property.second = value;
} }
void docpp::HTML::HTMLProperty::set(const std::pair<std::string, std::string>& property) { void docpp::HTML::Property::set(const std::pair<std::string, std::string>& property) {
this->property = property; this->property = property;
} }
docpp::HTML::HTMLProperties::HTMLProperties(const std::vector<docpp::HTML::HTMLProperty>& properties) { docpp::HTML::Properties::Properties(const std::vector<docpp::HTML::Property>& properties) {
this->set(properties); this->set(properties);
} }
docpp::HTML::HTMLProperties::HTMLProperties(const docpp::HTML::HTMLProperty& property) { docpp::HTML::Properties::Properties(const docpp::HTML::Property& property) {
this->push_back(property); this->push_back(property);
} }
docpp::HTML::HTMLProperties docpp::HTML::HTMLProperties::operator=(const docpp::HTML::HTMLProperty& property) { docpp::HTML::Properties docpp::HTML::Properties::operator=(const docpp::HTML::Property& property) {
this->properties = {property}; this->properties = {property};
return *this; return *this;
} }
docpp::HTML::HTMLProperties docpp::HTML::HTMLProperties::operator=(const docpp::HTML::HTMLProperties& properties) { docpp::HTML::Properties docpp::HTML::Properties::operator=(const docpp::HTML::Properties& properties) {
this->set(properties.getProperties()); this->set(properties.getProperties());
return *this; return *this;
} }
docpp::HTML::HTMLProperties docpp::HTML::HTMLProperties::operator=(const std::vector<docpp::HTML::HTMLProperty>& properties) { docpp::HTML::Properties docpp::HTML::Properties::operator=(const std::vector<docpp::HTML::Property>& properties) {
this->set(properties); this->set(properties);
return *this; return *this;
} }
void docpp::HTML::HTMLProperties::operator+=(const docpp::HTML::HTMLProperty& property) { void docpp::HTML::Properties::operator+=(const docpp::HTML::Property& property) {
this->push_back(property); this->push_back(property);
} }
std::vector<docpp::HTML::HTMLProperty> docpp::HTML::HTMLProperties::getProperties() const { std::vector<docpp::HTML::Property> docpp::HTML::Properties::getProperties() const {
return this->properties; return this->properties;
} }
docpp::HTML::HTMLProperty docpp::HTML::HTMLProperties::at(const int index) const { docpp::HTML::Property docpp::HTML::Properties::at(const int index) const {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -88,11 +88,11 @@ docpp::HTML::HTMLProperty docpp::HTML::HTMLProperties::at(const int index) const
return this->properties.at(index); return this->properties.at(index);
} }
void docpp::HTML::HTMLProperties::set(const std::vector<docpp::HTML::HTMLProperty>& properties) { void docpp::HTML::Properties::set(const std::vector<docpp::HTML::Property>& properties) {
this->properties = properties; this->properties = properties;
} }
void docpp::HTML::HTMLProperties::insert(const int index, const docpp::HTML::HTMLProperty& property) { void docpp::HTML::Properties::insert(const int index, const docpp::HTML::Property& property) {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -100,7 +100,7 @@ void docpp::HTML::HTMLProperties::insert(const int index, const docpp::HTML::HTM
this->properties.insert(this->properties.begin() + index, property); this->properties.insert(this->properties.begin() + index, property);
} }
void docpp::HTML::HTMLProperties::erase(const int index) { void docpp::HTML::Properties::erase(const int index) {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -108,15 +108,15 @@ void docpp::HTML::HTMLProperties::erase(const int index) {
this->properties.erase(this->properties.begin() + index); this->properties.erase(this->properties.begin() + index);
} }
void docpp::HTML::HTMLProperties::push_front(const docpp::HTML::HTMLProperty& property) { void docpp::HTML::Properties::push_front(const docpp::HTML::Property& property) {
this->properties.insert(this->properties.begin(), property); this->properties.insert(this->properties.begin(), property);
} }
void docpp::HTML::HTMLProperties::push_back(const docpp::HTML::HTMLProperty& property) { void docpp::HTML::Properties::push_back(const docpp::HTML::Property& property) {
this->properties.push_back(property); this->properties.push_back(property);
} }
int docpp::HTML::HTMLProperties::find(const docpp::HTML::HTMLProperty& property) { int docpp::HTML::Properties::find(const docpp::HTML::Property& property) {
for (int i{0}; i < this->properties.size(); i++) { for (int i{0}; i < this->properties.size(); i++) {
if (!this->properties.at(i).getKey().compare(property.getKey())) { if (!this->properties.at(i).getKey().compare(property.getKey())) {
return i; return i;
@ -131,10 +131,10 @@ int docpp::HTML::HTMLProperties::find(const docpp::HTML::HTMLProperty& property)
} }
} }
return docpp::HTML::HTMLProperties::npos; return docpp::HTML::Properties::npos;
} }
int docpp::HTML::HTMLProperties::find(const std::string& str) { int docpp::HTML::Properties::find(const std::string& str) {
for (int i{0}; i < this->properties.size(); i++) { for (int i{0}; i < this->properties.size(); i++) {
if (!this->properties.at(i).getKey().compare(str) || !this->properties.at(i).getValue().compare(str)) { if (!this->properties.at(i).getKey().compare(str) || !this->properties.at(i).getValue().compare(str)) {
return i; return i;
@ -143,22 +143,22 @@ int docpp::HTML::HTMLProperties::find(const std::string& str) {
} }
} }
return docpp::HTML::HTMLProperties::npos; return docpp::HTML::Properties::npos;
} }
docpp::HTML::HTMLProperty docpp::HTML::HTMLProperties::front() const { docpp::HTML::Property docpp::HTML::Properties::front() const {
return this->properties.front(); return this->properties.front();
} }
docpp::HTML::HTMLProperty docpp::HTML::HTMLProperties::back() const { docpp::HTML::Property docpp::HTML::Properties::back() const {
return this->properties.back(); return this->properties.back();
} }
int docpp::HTML::HTMLProperties::size() const { int docpp::HTML::Properties::size() const {
return this->properties.size(); return this->properties.size();
} }
void docpp::HTML::HTMLProperties::swap(const int index1, const int index2) { void docpp::HTML::Properties::swap(const int index1, const int index2) {
if (index1 < 0 || index1 >= this->properties.size() || index2 < 0 || index2 >= this->properties.size()) { if (index1 < 0 || index1 >= this->properties.size() || index2 < 0 || index2 >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -166,31 +166,31 @@ void docpp::HTML::HTMLProperties::swap(const int index1, const int index2) {
std::swap(this->properties[index1], this->properties[index2]); std::swap(this->properties[index1], this->properties[index2]);
} }
void docpp::HTML::HTMLProperties::swap(const docpp::HTML::HTMLProperty& property1, const docpp::HTML::HTMLProperty& property2) { void docpp::HTML::Properties::swap(const docpp::HTML::Property& property1, const docpp::HTML::Property& property2) {
this->swap(this->find(property1), this->find(property2)); this->swap(this->find(property1), this->find(property2));
} }
docpp::HTML::HTMLElement::HTMLElement(const std::string& tag, const HTMLProperties& properties, const std::string& data, const int type) { docpp::HTML::Element::Element(const std::string& tag, const Properties& properties, const std::string& data, const int type) {
this->set(tag, properties, data, type); this->set(tag, properties, data, type);
} }
docpp::HTML::HTMLElement docpp::HTML::HTMLElement::operator=(const docpp::HTML::HTMLElement& element) { docpp::HTML::Element docpp::HTML::Element::operator=(const docpp::HTML::Element& element) {
this->set(element.getTag(), element.properties, element.getData(), element.type); this->set(element.getTag(), element.properties, element.getData(), element.type);
return *this; return *this;
} }
void docpp::HTML::HTMLElement::operator+=(const std::string& data) { void docpp::HTML::Element::operator+=(const std::string& data) {
this->data += data; this->data += data;
} }
void docpp::HTML::HTMLElement::set(const std::string& tag, const HTMLProperties& properties, const std::string& data, const int type) { void docpp::HTML::Element::set(const std::string& tag, const Properties& properties, const std::string& data, const int type) {
this->tag = tag; this->tag = tag;
this->data = data; this->data = data;
this->properties = properties; this->properties = properties;
this->type = type; this->type = type;
} }
std::string docpp::HTML::HTMLElement::get(const int formatting, const int tabc) const { std::string docpp::HTML::Element::get(const int formatting, const int tabc) const {
std::string ret{}; std::string ret{};
if (this->type == docpp::HTML::TYPE_TEXT) { if (this->type == docpp::HTML::TYPE_TEXT) {
@ -235,20 +235,20 @@ std::string docpp::HTML::HTMLElement::get(const int formatting, const int tabc)
return std::move(ret); return std::move(ret);
} }
std::string docpp::HTML::HTMLElement::getTag() const { std::string docpp::HTML::Element::getTag() const {
return this->tag; return this->tag;
} }
std::string docpp::HTML::HTMLElement::getData() const { std::string docpp::HTML::Element::getData() const {
return this->data; return this->data;
} }
docpp::HTML::HTMLSection::HTMLSection(const std::string& tag, const HTMLProperties& properties) { docpp::HTML::Section::Section(const std::string& tag, const Properties& properties) {
this->tag = tag; this->tag = tag;
this->properties = properties; this->properties = properties;
} }
docpp::HTML::HTMLSection docpp::HTML::HTMLSection::operator=(const docpp::HTML::HTMLSection& section) { docpp::HTML::Section docpp::HTML::Section::operator=(const docpp::HTML::Section& section) {
this->tag = section.tag; this->tag = section.tag;
this->properties = section.properties; this->properties = section.properties;
this->elements = section.elements; this->elements = section.elements;
@ -258,28 +258,28 @@ docpp::HTML::HTMLSection docpp::HTML::HTMLSection::operator=(const docpp::HTML::
return *this; return *this;
} }
void docpp::HTML::HTMLSection::operator+=(const docpp::HTML::HTMLElement& element) { void docpp::HTML::Section::operator+=(const docpp::HTML::Element& element) {
this->push_back(element); this->push_back(element);
} }
void docpp::HTML::HTMLSection::operator+=(const docpp::HTML::HTMLSection& section) { void docpp::HTML::Section::operator+=(const docpp::HTML::Section& section) {
this->push_back(section); this->push_back(section);
} }
docpp::HTML::HTMLElement docpp::HTML::HTMLSection::operator[](const int& index) const { docpp::HTML::Element docpp::HTML::Section::operator[](const int& index) const {
return this->at(index); return this->at(index);
} }
docpp::HTML::HTMLSection::HTMLSection(const int tag, const HTMLProperties& properties) { docpp::HTML::Section::Section(const int tag, const Properties& properties) {
this->set(tag, properties); this->set(tag, properties);
} }
void docpp::HTML::HTMLSection::set(const std::string& tag, const HTMLProperties& properties) { void docpp::HTML::Section::set(const std::string& tag, const Properties& properties) {
this->tag = tag; this->tag = tag;
this->properties = properties; this->properties = properties;
} }
void docpp::HTML::HTMLSection::set(const int tag, const HTMLProperties& properties) { void docpp::HTML::Section::set(const int tag, const Properties& properties) {
if (tag == docpp::HTML::SECTION_DIV) { if (tag == docpp::HTML::SECTION_DIV) {
this->tag = "div"; this->tag = "div";
} else if (tag == docpp::HTML::SECTION_BODY) { } else if (tag == docpp::HTML::SECTION_BODY) {
@ -295,7 +295,7 @@ void docpp::HTML::HTMLSection::set(const int tag, const HTMLProperties& properti
this->properties = properties; this->properties = properties;
} }
void docpp::HTML::HTMLSection::push_front(const HTMLElement& element) { void docpp::HTML::Section::push_front(const Element& element) {
for (int i{this->index}; i > 0; i--) { for (int i{this->index}; i > 0; i--) {
this->elements[i] = this->elements.at(i - 1); this->elements[i] = this->elements.at(i - 1);
} }
@ -304,7 +304,7 @@ void docpp::HTML::HTMLSection::push_front(const HTMLElement& element) {
this->index++; this->index++;
} }
void docpp::HTML::HTMLSection::push_front(const HTMLSection& section) { void docpp::HTML::Section::push_front(const Section& section) {
for (int i{this->index}; i > 0; i--) { for (int i{this->index}; i > 0; i--) {
this->sections.at(i) = this->sections.at(i - 1); this->sections.at(i) = this->sections.at(i - 1);
} }
@ -313,15 +313,15 @@ void docpp::HTML::HTMLSection::push_front(const HTMLSection& section) {
this->index++; this->index++;
} }
void docpp::HTML::HTMLSection::push_back(const HTMLElement& element) { void docpp::HTML::Section::push_back(const Element& element) {
this->elements[this->index++] = element; this->elements[this->index++] = element;
} }
void docpp::HTML::HTMLSection::push_back(const HTMLSection& section) { void docpp::HTML::Section::push_back(const Section& section) {
this->sections[this->index++] = section; this->sections[this->index++] = section;
} }
void docpp::HTML::HTMLSection::erase(const int index) { void docpp::HTML::Section::erase(const int index) {
bool erased{false}; bool erased{false};
if (this->elements.find(index) != this->elements.end()) { if (this->elements.find(index) != this->elements.end()) {
@ -337,9 +337,9 @@ void docpp::HTML::HTMLSection::erase(const int index) {
} }
} }
void docpp::HTML::HTMLSection::erase(const HTMLSection& section) { void docpp::HTML::Section::erase(const Section& section) {
for (int i{0}; i < this->size(); i++) { for (int i{0}; i < this->size(); i++) {
const auto it = this->getHTMLSections().at(i); const auto it = this->getSections().at(i);
if (it.get() == section.get()) { if (it.get() == section.get()) {
this->erase(i); this->erase(i);
@ -350,9 +350,9 @@ void docpp::HTML::HTMLSection::erase(const HTMLSection& section) {
throw docpp::out_of_range("Section not found"); throw docpp::out_of_range("Section not found");
} }
void docpp::HTML::HTMLSection::erase(const HTMLElement& element) { void docpp::HTML::Section::erase(const Element& element) {
for (int i{0}; i < this->size(); i++) { for (int i{0}; i < this->size(); i++) {
const auto it = this->getHTMLElements().at(i); const auto it = this->getElements().at(i);
if (it.get() == element.get()) { if (it.get() == element.get()) {
this->erase(i); this->erase(i);
@ -363,7 +363,7 @@ void docpp::HTML::HTMLSection::erase(const HTMLElement& element) {
throw docpp::out_of_range("Element not found"); throw docpp::out_of_range("Element not found");
} }
void docpp::HTML::HTMLSection::insert(const int index, const HTMLElement& element) { void docpp::HTML::Section::insert(const int index, const Element& element) {
if (this->sections.find(index) != this->sections.end()) { if (this->sections.find(index) != this->sections.end()) {
throw docpp::invalid_argument("Index already occupied by a section"); throw docpp::invalid_argument("Index already occupied by a section");
} else { } else {
@ -373,12 +373,12 @@ void docpp::HTML::HTMLSection::insert(const int index, const HTMLElement& elemen
this->index = std::max(this->index, index) + 1; this->index = std::max(this->index, index) + 1;
} }
void docpp::HTML::HTMLSection::insert(const int index, const HTMLSection& section) { void docpp::HTML::Section::insert(const int index, const Section& section) {
this->sections[index] = section; this->sections[index] = section;
this->index = std::max(this->index, index) + 1; this->index = std::max(this->index, index) + 1;
} }
docpp::HTML::HTMLElement docpp::HTML::HTMLSection::at(const int index) const { docpp::HTML::Element docpp::HTML::Section::at(const int index) const {
if (this->elements.find(index) != this->elements.end()) { if (this->elements.find(index) != this->elements.end()) {
return this->elements.at(index); return this->elements.at(index);
} }
@ -386,7 +386,7 @@ docpp::HTML::HTMLElement docpp::HTML::HTMLSection::at(const int index) const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
docpp::HTML::HTMLSection docpp::HTML::HTMLSection::at_section(const int index) const { docpp::HTML::Section docpp::HTML::Section::at_section(const int index) const {
if (this->sections.find(index) != this->sections.end()) { if (this->sections.find(index) != this->sections.end()) {
return this->sections.at(index); return this->sections.at(index);
} }
@ -394,32 +394,32 @@ docpp::HTML::HTMLSection docpp::HTML::HTMLSection::at_section(const int index) c
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
int docpp::HTML::HTMLSection::find(const HTMLElement& element) { int docpp::HTML::Section::find(const Element& element) {
for (int i{0}; i < this->size(); i++) { for (int i{0}; i < this->size(); i++) {
const auto it = this->getHTMLElements().at(i); const auto it = this->getElements().at(i);
if (it.get() == element.get()) { if (it.get() == element.get()) {
return i; return i;
} }
} }
return docpp::HTML::HTMLSection::npos; return docpp::HTML::Section::npos;
} }
int docpp::HTML::HTMLSection::find(const HTMLSection& section) { int docpp::HTML::Section::find(const Section& section) {
for (int i{0}; i < this->size(); i++) { for (int i{0}; i < this->size(); i++) {
const auto it = this->getHTMLSections().at(i); const auto it = this->getSections().at(i);
if (it.get() == section.get()) { if (it.get() == section.get()) {
return i; return i;
} }
} }
return docpp::HTML::HTMLSection::npos; return docpp::HTML::Section::npos;
} }
int docpp::HTML::HTMLSection::find(const std::string& str) { int docpp::HTML::Section::find(const std::string& str) {
const auto elements = this->getHTMLElements(); const auto elements = this->getElements();
for (int i{0}; i < elements.size(); i++) { for (int i{0}; i < elements.size(); i++) {
if (!elements.at(i).get().compare(str)) { if (!elements.at(i).get().compare(str)) {
@ -427,7 +427,7 @@ int docpp::HTML::HTMLSection::find(const std::string& str) {
} }
} }
const auto sections = this->getHTMLSections(); const auto sections = this->getSections();
for (int i{0}; i < sections.size(); i++) { for (int i{0}; i < sections.size(); i++) {
if (!sections.at(i).get().compare(str)) { if (!sections.at(i).get().compare(str)) {
@ -435,10 +435,10 @@ int docpp::HTML::HTMLSection::find(const std::string& str) {
} }
} }
return docpp::HTML::HTMLSection::npos; return docpp::HTML::Section::npos;
} }
docpp::HTML::HTMLElement docpp::HTML::HTMLSection::front() const { docpp::HTML::Element docpp::HTML::Section::front() const {
if (this->elements.find(0) != this->elements.end()) { if (this->elements.find(0) != this->elements.end()) {
return this->elements.at(0); return this->elements.at(0);
} }
@ -446,7 +446,7 @@ docpp::HTML::HTMLElement docpp::HTML::HTMLSection::front() const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
docpp::HTML::HTMLSection docpp::HTML::HTMLSection::front_section() const { docpp::HTML::Section docpp::HTML::Section::front_section() const {
if (this->sections.find(0) != this->sections.end()) { if (this->sections.find(0) != this->sections.end()) {
return this->sections.at(0); return this->sections.at(0);
} }
@ -454,7 +454,7 @@ docpp::HTML::HTMLSection docpp::HTML::HTMLSection::front_section() const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
docpp::HTML::HTMLElement docpp::HTML::HTMLSection::back() const { docpp::HTML::Element docpp::HTML::Section::back() const {
if (this->elements.find(this->index - 1) != this->elements.end()) { if (this->elements.find(this->index - 1) != this->elements.end()) {
return this->elements.at(this->index - 1); return this->elements.at(this->index - 1);
} }
@ -462,7 +462,7 @@ docpp::HTML::HTMLElement docpp::HTML::HTMLSection::back() const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
docpp::HTML::HTMLSection docpp::HTML::HTMLSection::back_section() const { docpp::HTML::Section docpp::HTML::Section::back_section() const {
if (this->sections.find(this->index - 1) != this->sections.end()) { if (this->sections.find(this->index - 1) != this->sections.end()) {
return this->sections.at(this->index - 1); return this->sections.at(this->index - 1);
} }
@ -470,12 +470,12 @@ docpp::HTML::HTMLSection docpp::HTML::HTMLSection::back_section() const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
int docpp::HTML::HTMLSection::size() const { int docpp::HTML::Section::size() const {
return this->index; return this->index;
} }
std::vector<docpp::HTML::HTMLElement> docpp::HTML::HTMLSection::getHTMLElements() const { std::vector<docpp::HTML::Element> docpp::HTML::Section::getElements() const {
std::vector<docpp::HTML::HTMLElement> ret{}; std::vector<docpp::HTML::Element> ret{};
ret.reserve(this->index); ret.reserve(this->index);
for (int i{0}; i < this->index; i++) { for (int i{0}; i < this->index; i++) {
if (this->elements.find(i) != this->elements.end()) { if (this->elements.find(i) != this->elements.end()) {
@ -485,8 +485,8 @@ std::vector<docpp::HTML::HTMLElement> docpp::HTML::HTMLSection::getHTMLElements(
return std::move(ret); return std::move(ret);
} }
std::vector<docpp::HTML::HTMLSection> docpp::HTML::HTMLSection::getHTMLSections() const { std::vector<docpp::HTML::Section> docpp::HTML::Section::getSections() const {
std::vector<docpp::HTML::HTMLSection> ret{}; std::vector<docpp::HTML::Section> ret{};
ret.reserve(this->index); ret.reserve(this->index);
for (int i{0}; i < this->index; i++) { for (int i{0}; i < this->index; i++) {
@ -498,7 +498,7 @@ std::vector<docpp::HTML::HTMLSection> docpp::HTML::HTMLSection::getHTMLSections(
return std::move(ret); return std::move(ret);
} }
std::string docpp::HTML::HTMLSection::get(const int formatting, const int tabc) const { std::string docpp::HTML::Section::get(const int formatting, const int tabc) const {
std::string ret{}; std::string ret{};
int tabcount{tabc}; int tabcount{tabc};
@ -556,7 +556,7 @@ std::string docpp::HTML::HTMLSection::get(const int formatting, const int tabc)
return std::move(ret); return std::move(ret);
} }
void docpp::HTML::HTMLSection::swap(const int index1, const int index2) { void docpp::HTML::Section::swap(const int index1, const int index2) {
if (this->elements.find(index1) != this->elements.end() && this->elements.find(index2) != this->elements.end()) { if (this->elements.find(index1) != this->elements.end() && this->elements.find(index2) != this->elements.end()) {
std::swap(this->elements[index1], this->elements[index2]); std::swap(this->elements[index1], this->elements[index2]);
} else if (this->sections.find(index1) != this->sections.end() && this->sections.find(index2) != this->sections.end()) { } else if (this->sections.find(index1) != this->sections.end() && this->sections.find(index2) != this->sections.end()) {
@ -566,135 +566,135 @@ void docpp::HTML::HTMLSection::swap(const int index1, const int index2) {
} }
} }
void docpp::HTML::HTMLSection::swap(const HTMLElement& element1, const HTMLElement& element2) { void docpp::HTML::Section::swap(const Element& element1, const Element& element2) {
this->swap(this->find(element1), this->find(element2)); this->swap(this->find(element1), this->find(element2));
} }
void docpp::HTML::HTMLSection::swap(const HTMLSection& section1, const HTMLSection& section2) { void docpp::HTML::Section::swap(const Section& section1, const Section& section2) {
this->swap(this->find(section1), this->find(section2)); this->swap(this->find(section1), this->find(section2));
} }
std::string docpp::HTML::HTMLDocument::get(const int formatting, const int tabc) const { std::string docpp::HTML::Document::get(const int formatting, const int tabc) const {
return this->doctype + (formatting == FORMATTING_PRETTY ? "\n" : formatting == FORMATTING_NEWLINE ? "\n" : "") + this->document.get(formatting, tabc); return this->doctype + (formatting == FORMATTING_PRETTY ? "\n" : formatting == FORMATTING_NEWLINE ? "\n" : "") + this->document.get(formatting, tabc);
} }
docpp::HTML::HTMLSection& docpp::HTML::HTMLDocument::getSection() { docpp::HTML::Section& docpp::HTML::Document::getSection() {
return this->document; return this->document;
} }
void docpp::HTML::HTMLDocument::set(const docpp::HTML::HTMLSection& document) { void docpp::HTML::Document::set(const docpp::HTML::Section& document) {
this->document = document; this->document = document;
} }
void docpp::HTML::HTMLDocument::setDoctype(const std::string& doctype) { void docpp::HTML::Document::setDoctype(const std::string& doctype) {
this->doctype = doctype; this->doctype = doctype;
} }
docpp::HTML::HTMLDocument docpp::HTML::HTMLDocument::operator=(const docpp::HTML::HTMLDocument& document) { docpp::HTML::Document docpp::HTML::Document::operator=(const docpp::HTML::Document& document) {
this->set(document.get()); this->set(document.get());
this->setDoctype(document.getDoctype()); this->setDoctype(document.getDoctype());
return *this; return *this;
} }
docpp::HTML::HTMLDocument docpp::HTML::HTMLDocument::operator=(const docpp::HTML::HTMLSection& section) { docpp::HTML::Document docpp::HTML::Document::operator=(const docpp::HTML::Section& section) {
this->set(section); this->set(section);
return *this; return *this;
} }
docpp::HTML::HTMLDocument::HTMLDocument(const docpp::HTML::HTMLSection& document, const std::string& doctype) { docpp::HTML::Document::Document(const docpp::HTML::Section& document, const std::string& doctype) {
this->set(document); this->set(document);
this->setDoctype(doctype); this->setDoctype(doctype);
} }
std::string docpp::HTML::HTMLDocument::getDoctype() const { std::string docpp::HTML::Document::getDoctype() const {
return this->doctype; return this->doctype;
} }
docpp::CSS::CSSProperty::CSSProperty(const std::string& key, const std::string& value) { docpp::CSS::Property::Property(const std::string& key, const std::string& value) {
this->set(key, value); this->set(key, value);
} }
docpp::CSS::CSSProperty::CSSProperty(const std::pair<std::string, std::string>& property) { docpp::CSS::Property::Property(const std::pair<std::string, std::string>& property) {
this->set(property); this->set(property);
} }
std::string docpp::CSS::CSSProperty::getKey() const { std::string docpp::CSS::Property::getKey() const {
return this->property.first; return this->property.first;
} }
std::string docpp::CSS::CSSProperty::getValue() const { std::string docpp::CSS::Property::getValue() const {
return this->property.second; return this->property.second;
} }
std::pair<std::string, std::string> docpp::CSS::CSSProperty::get() const { std::pair<std::string, std::string> docpp::CSS::Property::get() const {
return this->property; return this->property;
} }
void docpp::CSS::CSSProperty::setKey(const std::string& key) { void docpp::CSS::Property::setKey(const std::string& key) {
this->property.first = key; this->property.first = key;
} }
void docpp::CSS::CSSProperty::setValue(const std::string& value) { void docpp::CSS::Property::setValue(const std::string& value) {
this->property.second = value; this->property.second = value;
} }
void docpp::CSS::CSSProperty::set(const std::pair<std::string, std::string>& property) { void docpp::CSS::Property::set(const std::pair<std::string, std::string>& property) {
this->property = property; this->property = property;
} }
void docpp::CSS::CSSProperty::set(const std::string& key, const std::string& value) { void docpp::CSS::Property::set(const std::string& key, const std::string& value) {
this->property = std::make_pair(key, value); this->property = std::make_pair(key, value);
} }
docpp::CSS::CSSProperty docpp::CSS::CSSProperty::operator=(const docpp::CSS::CSSProperty& property) { docpp::CSS::Property docpp::CSS::Property::operator=(const docpp::CSS::Property& property) {
this->set(property.get()); this->set(property.get());
return *this; return *this;
} }
docpp::CSS::CSSProperty docpp::CSS::CSSProperty::operator=(const std::pair<std::string, std::string>& property) { docpp::CSS::Property docpp::CSS::Property::operator=(const std::pair<std::string, std::string>& property) {
this->set(property); this->set(property);
return *this; return *this;
} }
docpp::CSS::CSSElement::CSSElement(const std::string& tag, const std::vector<CSSProperty>& properties) { docpp::CSS::Element::Element(const std::string& tag, const std::vector<Property>& properties) {
this->set(tag, properties); this->set(tag, properties);
} }
docpp::CSS::CSSElement::CSSElement(const std::pair<std::string, std::vector<CSSProperty>>& element) { docpp::CSS::Element::Element(const std::pair<std::string, std::vector<Property>>& element) {
this->set(element); this->set(element);
} }
docpp::CSS::CSSElement docpp::CSS::CSSElement::operator=(const docpp::CSS::CSSElement& element) { docpp::CSS::Element docpp::CSS::Element::operator=(const docpp::CSS::Element& element) {
this->set({element.getTag(), element.getProperties()}); this->set({element.getTag(), element.getProperties()});
return *this; return *this;
} }
void docpp::CSS::CSSElement::operator+=(const CSSProperty& property) { void docpp::CSS::Element::operator+=(const Property& property) {
this->push_back(property); this->push_back(property);
} }
docpp::CSS::CSSProperty docpp::CSS::CSSElement::operator[](const int& index) const { docpp::CSS::Property docpp::CSS::Element::operator[](const int& index) const {
return this->at(index); return this->at(index);
} }
void docpp::CSS::CSSElement::set(const std::string& tag, const std::vector<CSSProperty>& properties) { void docpp::CSS::Element::set(const std::string& tag, const std::vector<Property>& properties) {
this->element.first = tag; this->element.first = tag;
this->element.second = properties; this->element.second = properties;
} }
void docpp::CSS::CSSElement::set(const std::pair<std::string, std::vector<CSSProperty>>& element) { void docpp::CSS::Element::set(const std::pair<std::string, std::vector<Property>>& element) {
this->element = element; this->element = element;
} }
void docpp::CSS::CSSElement::push_front(const CSSProperty& property) { void docpp::CSS::Element::push_front(const Property& property) {
this->element.second.insert(this->element.second.begin(), property); this->element.second.insert(this->element.second.begin(), property);
} }
void docpp::CSS::CSSElement::push_back(const CSSProperty& property) { void docpp::CSS::Element::push_back(const Property& property) {
this->element.second.push_back(property); this->element.second.push_back(property);
} }
void docpp::CSS::CSSElement::insert(const int index, const CSSProperty& property) { void docpp::CSS::Element::insert(const int index, const Property& property) {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -702,7 +702,7 @@ void docpp::CSS::CSSElement::insert(const int index, const CSSProperty& property
this->element.second.insert(this->element.second.begin() + index, property); this->element.second.insert(this->element.second.begin() + index, property);
} }
void docpp::CSS::CSSElement::erase(const int index) { void docpp::CSS::Element::erase(const int index) {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -710,7 +710,7 @@ void docpp::CSS::CSSElement::erase(const int index) {
this->element.second.erase(this->element.second.begin() + index); this->element.second.erase(this->element.second.begin() + index);
} }
docpp::CSS::CSSProperty docpp::CSS::CSSElement::at(const int index) const { docpp::CSS::Property docpp::CSS::Element::at(const int index) const {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -718,39 +718,39 @@ docpp::CSS::CSSProperty docpp::CSS::CSSElement::at(const int index) const {
return this->element.second.at(index); return this->element.second.at(index);
} }
int docpp::CSS::CSSElement::find(const CSSProperty& property) { int docpp::CSS::Element::find(const Property& property) {
for (int i{0}; i < this->element.second.size(); i++) { for (int i{0}; i < this->element.second.size(); i++) {
if (this->element.second.at(i).get() == property.get()) { if (this->element.second.at(i).get() == property.get()) {
return i; return i;
} }
} }
return docpp::CSS::CSSElement::npos; return docpp::CSS::Element::npos;
} }
int docpp::CSS::CSSElement::find(const std::string& str) { int docpp::CSS::Element::find(const std::string& str) {
for (int i{0}; i < this->element.second.size(); i++) { for (int i{0}; i < this->element.second.size(); i++) {
if (!this->element.second.at(i).getKey().compare(str) || !this->element.second.at(i).getValue().compare(str)) { if (!this->element.second.at(i).getKey().compare(str) || !this->element.second.at(i).getValue().compare(str)) {
return i; return i;
} }
} }
return docpp::CSS::CSSElement::npos; return docpp::CSS::Element::npos;
} }
docpp::CSS::CSSProperty docpp::CSS::CSSElement::front() const { docpp::CSS::Property docpp::CSS::Element::front() const {
return this->element.second.front(); return this->element.second.front();
} }
docpp::CSS::CSSProperty docpp::CSS::CSSElement::back() const { docpp::CSS::Property docpp::CSS::Element::back() const {
return this->element.second.back(); return this->element.second.back();
} }
int docpp::CSS::CSSElement::size() const { int docpp::CSS::Element::size() const {
return this->element.second.size(); return this->element.second.size();
} }
void docpp::CSS::CSSElement::swap(const int index1, const int index2) { void docpp::CSS::Element::swap(const int index1, const int index2) {
if (index1 < 0 || index1 >= this->element.second.size() || index2 < 0 || index2 >= this->element.second.size()) { if (index1 < 0 || index1 >= this->element.second.size() || index2 < 0 || index2 >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -758,11 +758,11 @@ void docpp::CSS::CSSElement::swap(const int index1, const int index2) {
std::swap(this->element.second[index1], this->element.second[index2]); std::swap(this->element.second[index1], this->element.second[index2]);
} }
void docpp::CSS::CSSElement::swap(const CSSProperty& property1, const CSSProperty& property2) { void docpp::CSS::Element::swap(const Property& property1, const Property& property2) {
this->swap(this->find(property1), this->find(property2)); this->swap(this->find(property1), this->find(property2));
} }
std::string docpp::CSS::CSSElement::get(const int formatting, const int tabc) const { std::string docpp::CSS::Element::get(const int formatting, const int tabc) const {
std::string ret{}; std::string ret{};
if (this->element.first.compare("")) { if (this->element.first.compare("")) {
@ -799,31 +799,31 @@ std::string docpp::CSS::CSSElement::get(const int formatting, const int tabc) co
return std::move(ret); return std::move(ret);
} }
std::string docpp::CSS::CSSElement::getTag() const { std::string docpp::CSS::Element::getTag() const {
return this->element.first; return this->element.first;
} }
std::vector<docpp::CSS::CSSProperty> docpp::CSS::CSSElement::getProperties() const { std::vector<docpp::CSS::Property> docpp::CSS::Element::getProperties() const {
return this->element.second; return this->element.second;
} }
docpp::CSS::CSSStylesheet::CSSStylesheet(const std::vector<CSSElement>& elements) { docpp::CSS::Stylesheet::Stylesheet(const std::vector<Element>& elements) {
this->set(elements); this->set(elements);
} }
void docpp::CSS::CSSStylesheet::set(const std::vector<CSSElement>& elements) { void docpp::CSS::Stylesheet::set(const std::vector<Element>& elements) {
this->elements = elements; this->elements = elements;
} }
void docpp::CSS::CSSStylesheet::push_front(const CSSElement& element) { void docpp::CSS::Stylesheet::push_front(const Element& element) {
this->elements.insert(this->elements.begin(), element); this->elements.insert(this->elements.begin(), element);
} }
void docpp::CSS::CSSStylesheet::push_back(const CSSElement& element) { void docpp::CSS::Stylesheet::push_back(const Element& element) {
this->elements.push_back(element); this->elements.push_back(element);
} }
void docpp::CSS::CSSStylesheet::insert(const int index, const CSSElement& element) { void docpp::CSS::Stylesheet::insert(const int index, const Element& element) {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -831,7 +831,7 @@ void docpp::CSS::CSSStylesheet::insert(const int index, const CSSElement& elemen
this->elements.insert(this->elements.begin() + index, element); this->elements.insert(this->elements.begin() + index, element);
} }
void docpp::CSS::CSSStylesheet::erase(const int index) { void docpp::CSS::Stylesheet::erase(const int index) {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -839,20 +839,20 @@ void docpp::CSS::CSSStylesheet::erase(const int index) {
this->elements.erase(this->elements.begin() + index); this->elements.erase(this->elements.begin() + index);
} }
docpp::CSS::CSSStylesheet docpp::CSS::CSSStylesheet::operator=(const docpp::CSS::CSSStylesheet& stylesheet) { docpp::CSS::Stylesheet docpp::CSS::Stylesheet::operator=(const docpp::CSS::Stylesheet& stylesheet) {
this->set(stylesheet.getElements()); this->set(stylesheet.getElements());
return *this; return *this;
} }
void docpp::CSS::CSSStylesheet::operator+=(const CSSElement& element) { void docpp::CSS::Stylesheet::operator+=(const Element& element) {
this->push_back(element); this->push_back(element);
} }
docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::operator[](const int& index) const { docpp::CSS::Element docpp::CSS::Stylesheet::operator[](const int& index) const {
return this->at(index); return this->at(index);
} }
docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::at(const int index) const { docpp::CSS::Element docpp::CSS::Stylesheet::at(const int index) const {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -860,39 +860,39 @@ docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::at(const int index) const {
return this->elements.at(index); return this->elements.at(index);
} }
int docpp::CSS::CSSStylesheet::find(const CSSElement& element) { int docpp::CSS::Stylesheet::find(const Element& element) {
for (int i{0}; i < this->elements.size(); i++) { for (int i{0}; i < this->elements.size(); i++) {
if (this->elements.at(i).get() == element.get()) { if (this->elements.at(i).get() == element.get()) {
return i; return i;
} }
} }
return docpp::CSS::CSSStylesheet::npos; return docpp::CSS::Stylesheet::npos;
} }
int docpp::CSS::CSSStylesheet::find(const std::string& str) { int docpp::CSS::Stylesheet::find(const std::string& str) {
for (int i{0}; i < this->elements.size(); i++) { for (int i{0}; i < this->elements.size(); i++) {
if (!this->elements.at(i).get().compare(str) || !this->elements.at(i).getTag().compare(str)) { if (!this->elements.at(i).get().compare(str) || !this->elements.at(i).getTag().compare(str)) {
return i; return i;
} }
} }
return docpp::CSS::CSSStylesheet::npos; return docpp::CSS::Stylesheet::npos;
} }
int docpp::CSS::CSSStylesheet::size() const { int docpp::CSS::Stylesheet::size() const {
return this->elements.size(); return this->elements.size();
} }
docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::front() const { docpp::CSS::Element docpp::CSS::Stylesheet::front() const {
return this->elements.front(); return this->elements.front();
} }
docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::back() const { docpp::CSS::Element docpp::CSS::Stylesheet::back() const {
return this->elements.back(); return this->elements.back();
} }
void docpp::CSS::CSSStylesheet::swap(const int index1, const int index2) { void docpp::CSS::Stylesheet::swap(const int index1, const int index2) {
if (index1 < 0 || index1 >= this->elements.size() || index2 < 0 || index2 >= this->elements.size()) { if (index1 < 0 || index1 >= this->elements.size() || index2 < 0 || index2 >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -900,15 +900,15 @@ void docpp::CSS::CSSStylesheet::swap(const int index1, const int index2) {
std::swap(this->elements[index1], this->elements[index2]); std::swap(this->elements[index1], this->elements[index2]);
} }
void docpp::CSS::CSSStylesheet::swap(const CSSElement& element1, const CSSElement& element2) { void docpp::CSS::Stylesheet::swap(const Element& element1, const Element& element2) {
this->swap(this->find(element1), this->find(element2)); this->swap(this->find(element1), this->find(element2));
} }
std::vector<docpp::CSS::CSSElement> docpp::CSS::CSSStylesheet::getElements() const { std::vector<docpp::CSS::Element> docpp::CSS::Stylesheet::getElements() const {
return this->elements; return this->elements;
} }
std::string docpp::CSS::CSSStylesheet::get(const int formatting, const int tabc) const { std::string docpp::CSS::Stylesheet::get(const int formatting, const int tabc) const {
std::string ret{}; std::string ret{};
for (const auto& it : this->elements) { for (const auto& it : this->elements) {

View file

@ -8,29 +8,29 @@
*/ */
SCENARIO("Test HTML", "[HTML]") { SCENARIO("Test HTML", "[HTML]") {
const auto test1 = []() { const auto test1 = []() {
docpp::HTML::HTMLDocument doc{}; docpp::HTML::Document doc{};
docpp::HTML::HTMLSection html(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section html(docpp::HTML::SECTION_HTML, {});
docpp::HTML::HTMLSection head(docpp::HTML::SECTION_HEAD, {}); docpp::HTML::Section head(docpp::HTML::SECTION_HEAD, {});
docpp::HTML::HTMLSection body(docpp::HTML::SECTION_BODY, {}); docpp::HTML::Section body(docpp::HTML::SECTION_BODY, {});
docpp::HTML::HTMLSection div(docpp::HTML::SECTION_DIV, {}); docpp::HTML::Section div(docpp::HTML::SECTION_DIV, {});
docpp::HTML::HTMLSection footer(docpp::HTML::SECTION_FOOTER, {}); docpp::HTML::Section footer(docpp::HTML::SECTION_FOOTER, {});
head.push_back(docpp::HTML::HTMLElement("title", {}, "Test Title")); head.push_back(docpp::HTML::Element("title", {}, "Test Title"));
body.push_back(docpp::HTML::HTMLElement("h1", {}, "Test Header")); body.push_back(docpp::HTML::Element("h1", {}, "Test Header"));
body.push_back(docpp::HTML::HTMLElement("p", {}, "Test Paragraph")); body.push_back(docpp::HTML::Element("p", {}, "Test Paragraph"));
docpp::HTML::HTMLProperties prop{}; docpp::HTML::Properties prop{};
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("id", "test_id"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("id", "test_id")));
body.push_back(docpp::HTML::HTMLElement("p", prop, "Test Paragraph With ID")); body.push_back(docpp::HTML::Element("p", prop, "Test Paragraph With ID"));
div.push_back(docpp::HTML::HTMLElement("p", {}, "Test Paragraph In Div")); div.push_back(docpp::HTML::Element("p", {}, "Test Paragraph In Div"));
body.push_back(div); body.push_back(div);
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("class", "class1 class2 class3"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("class", "class1 class2 class3")));
body.push_back(docpp::HTML::HTMLElement("p", prop, "Test Paragraph With ID And Class")); body.push_back(docpp::HTML::Element("p", prop, "Test Paragraph With ID And Class"));
html.push_back(head); html.push_back(head);
html.push_back(body); html.push_back(body);
@ -45,40 +45,40 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test2 = []() { const auto test2 = []() {
docpp::HTML::HTMLSection section(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
section.erase(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.erase(docpp::HTML::Element("p", {}, "Test 2"));
REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p></html>"); REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p></html>");
REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "<html>\n<p>Test 1</p>\n<p>Test 3</p>\n</html>"); REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "<html>\n<p>Test 1</p>\n<p>Test 3</p>\n</html>");
}; };
const auto test3 = []() { const auto test3 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
int pos = section.find(docpp::HTML::HTMLElement("p", {}, "Test 2")); int pos = section.find(docpp::HTML::Element("p", {}, "Test 2"));
section.insert(pos, docpp::HTML::HTMLElement("p", {}, "Test 2.5")); section.insert(pos, docpp::HTML::Element("p", {}, "Test 2.5"));
REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 2.5</p><p>Test 3</p></html>"); REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 2.5</p><p>Test 3</p></html>");
REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "<html>\n<p>Test 1</p>\n<p>Test 2.5</p>\n<p>Test 3</p>\n</html>"); REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "<html>\n<p>Test 1</p>\n<p>Test 2.5</p>\n<p>Test 3</p>\n</html>");
}; };
const auto test4 = []() { const auto test4 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
int pos = section.find(docpp::HTML::HTMLElement("p", {}, "Test 2")); int pos = section.find(docpp::HTML::Element("p", {}, "Test 2"));
section.erase(pos); section.erase(pos);
@ -87,19 +87,19 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test5 = []() { const auto test5 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
docpp::HTML::HTMLSection subsection(docpp::HTML::SECTION_DIV, {}); docpp::HTML::Section subsection(docpp::HTML::SECTION_DIV, {});
subsection.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); subsection.push_back(docpp::HTML::Element("p", {}, "Test 1"));
docpp::HTML::HTMLSection subsection2(docpp::HTML::SECTION_DIV, {}); docpp::HTML::Section subsection2(docpp::HTML::SECTION_DIV, {});
subsection2.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); subsection2.push_back(docpp::HTML::Element("p", {}, "Test 2"));
subsection.push_back(subsection2); subsection.push_back(subsection2);
section.push_back(subsection); section.push_back(subsection);
docpp::HTML::HTMLDocument doc{}; docpp::HTML::Document doc{};
doc.set(section); doc.set(section);
REQUIRE(doc.get() == "<!DOCTYPE html><html><div><p>Test 1</p><div><p>Test 2</p></div></div></html>"); REQUIRE(doc.get() == "<!DOCTYPE html><html><div><p>Test 1</p><div><p>Test 2</p></div></div></html>");
@ -107,8 +107,8 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test6 = []() { const auto test6 = []() {
docpp::CSS::CSSStylesheet css{}; docpp::CSS::Stylesheet css{};
docpp::CSS::CSSElement element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}};
css.push_back(element); css.push_back(element);
@ -117,9 +117,9 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test7 = []() { const auto test7 = []() {
docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{};
docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}};
docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}};
css.push_back(element); css.push_back(element);
css.push_front(element2); css.push_front(element2);
@ -128,9 +128,9 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test8 = []() { const auto test8 = []() {
docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{};
docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}};
docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}};
css.push_back(element); css.push_back(element);
css.push_front(element2); css.push_front(element2);
@ -141,9 +141,9 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test9 = []() { const auto test9 = []() {
docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{};
docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}};
docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}};
css.push_back(element); css.push_back(element);
css.push_front(element2); css.push_front(element2);
@ -155,60 +155,60 @@ SCENARIO("Test HTML", "[HTML]") {
REQUIRE(css.get() == "p {color: red;font-size: 16px;font-family: Arial;}div {color: blue;font-size: 12px;font-family: Arial;}"); REQUIRE(css.get() == "p {color: red;font-size: 16px;font-family: Arial;}div {color: blue;font-size: 12px;font-family: Arial;}");
element.push_front(docpp::CSS::CSSProperty("font-weight", "bold")); element.push_front(docpp::CSS::Property("font-weight", "bold"));
REQUIRE(element.get() == "p {font-weight: bold;color: red;font-size: 16px;font-family: Arial;}"); REQUIRE(element.get() == "p {font-weight: bold;color: red;font-size: 16px;font-family: Arial;}");
}; };
const auto test10 = []() { const auto test10 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
section.swap(section.find(docpp::HTML::HTMLElement("p", {}, "Test 2")), section.find(docpp::HTML::HTMLElement("p", {}, "Test 3"))); section.swap(section.find(docpp::HTML::Element("p", {}, "Test 2")), section.find(docpp::HTML::Element("p", {}, "Test 3")));
REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html>"); REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html>");
}; };
const auto test11 = []() { const auto test11 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
section.swap(docpp::HTML::HTMLElement("p", {}, "Test 2"), docpp::HTML::HTMLElement("p", {}, "Test 3")); section.swap(docpp::HTML::Element("p", {}, "Test 2"), docpp::HTML::Element("p", {}, "Test 3"));
REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html>"); REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 3</p><p>Test 2</p></html>");
}; };
const auto test12 = []() { const auto test12 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
section.push_front(docpp::HTML::HTMLElement("p", {}, "Test 0")); section.push_front(docpp::HTML::Element("p", {}, "Test 0"));
REQUIRE(section.get() == "<html><p>Test 0</p><p>Test 1</p><p>Test 2</p><p>Test 3</p></html>"); REQUIRE(section.get() == "<html><p>Test 0</p><p>Test 1</p><p>Test 2</p><p>Test 3</p></html>");
}; };
const auto test13 = []() { const auto test13 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 4")); section.push_back(docpp::HTML::Element("p", {}, "Test 4"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 5")); section.push_back(docpp::HTML::Element("p", {}, "Test 5"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 6")); section.push_back(docpp::HTML::Element("p", {}, "Test 6"));
const int pos{section.find("<p>Test 2</p>")}; const int pos{section.find("<p>Test 2</p>")};
REQUIRE(pos != docpp::HTML::HTMLSection::npos); REQUIRE(pos != docpp::HTML::Section::npos);
const int pos2{section.find("<p>Test 6</p>")}; const int pos2{section.find("<p>Test 6</p>")};
@ -219,118 +219,118 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test14 = []() { const auto test14 = []() {
docpp::CSS::CSSElement element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; docpp::CSS::Element element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}};
const int red = element.find("color"); const int red = element.find("color");
REQUIRE(red != docpp::CSS::CSSElement::npos); REQUIRE(red != docpp::CSS::Element::npos);
const int blue = element.find("blue"); const int blue = element.find("blue");
REQUIRE(blue == docpp::CSS::CSSElement::npos); REQUIRE(blue == docpp::CSS::Element::npos);
element.erase(red); element.erase(red);
REQUIRE(element.get() == "p {font-size: 16px;font-family: Arial;}"); REQUIRE(element.get() == "p {font-size: 16px;font-family: Arial;}");
element.insert(red, docpp::CSS::CSSProperty("color", "red")); element.insert(red, docpp::CSS::Property("color", "red"));
REQUIRE(element.get() == "p {color: red;font-size: 16px;font-family: Arial;}"); REQUIRE(element.get() == "p {color: red;font-size: 16px;font-family: Arial;}");
}; };
const auto test15 = []() { const auto test15 = []() {
docpp::HTML::HTMLProperties prop{}; docpp::HTML::Properties prop{};
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("id", "test_id"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("id", "test_id")));
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("class", "class1 class2 class3"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("class", "class1 class2 class3")));
REQUIRE(docpp::HTML::HTMLElement("p", prop, {}).get() == "<p id=\"test_id\" class=\"class1 class2 class3\"></p>"); REQUIRE(docpp::HTML::Element("p", prop, {}).get() == "<p id=\"test_id\" class=\"class1 class2 class3\"></p>");
const int pos = prop.find("class"); const int pos = prop.find("class");
REQUIRE(pos != docpp::HTML::HTMLProperties::npos); REQUIRE(pos != docpp::HTML::Properties::npos);
const int pos2 = prop.find("class2"); const int pos2 = prop.find("class2");
REQUIRE(prop.at(pos2).getKey() == "class"); REQUIRE(prop.at(pos2).getKey() == "class");
REQUIRE(prop.at(pos2).getValue() == "class1 class2 class3"); REQUIRE(prop.at(pos2).getValue() == "class1 class2 class3");
REQUIRE(pos2 != docpp::HTML::HTMLProperties::npos); REQUIRE(pos2 != docpp::HTML::Properties::npos);
const int pos3 = prop.find("class4"); const int pos3 = prop.find("class4");
REQUIRE(pos3 == docpp::HTML::HTMLProperties::npos); REQUIRE(pos3 == docpp::HTML::Properties::npos);
prop.erase(pos); prop.erase(pos);
REQUIRE(docpp::HTML::HTMLElement("p", prop, {}).get() == "<p id=\"test_id\"></p>"); REQUIRE(docpp::HTML::Element("p", prop, {}).get() == "<p id=\"test_id\"></p>");
}; };
const auto test16 = []() { const auto test16 = []() {
docpp::HTML::HTMLDocument doc = docpp::HTML::HTMLSection({}); docpp::HTML::Document doc = docpp::HTML::Section({});
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 1"));
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 2"));
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 3"));
doc.getSection() = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); doc.getSection() = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 4")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 4"));
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 5")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 5"));
doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 6")); doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 6"));
doc.getSection() += docpp::HTML::HTMLElement("p", {}, "Test 7"); doc.getSection() += docpp::HTML::Element("p", {}, "Test 7");
REQUIRE(doc.get() == "<!DOCTYPE html><html><p>Test 4</p><p>Test 5</p><p>Test 6</p><p>Test 7</p></html>"); REQUIRE(doc.get() == "<!DOCTYPE html><html><p>Test 4</p><p>Test 5</p><p>Test 6</p><p>Test 7</p></html>");
}; };
const auto test17 = []() { const auto test17 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
docpp::HTML::HTMLDocument doc{section}; docpp::HTML::Document doc{section};
REQUIRE(doc.get(docpp::HTML::FORMATTING_PRETTY) == "<!DOCTYPE html>\n<html>\n\t<p>Test 1</p>\n\t<p>Test 2</p>\n\t<p>Test 3</p>\n</html>"); REQUIRE(doc.get(docpp::HTML::FORMATTING_PRETTY) == "<!DOCTYPE html>\n<html>\n\t<p>Test 1</p>\n\t<p>Test 2</p>\n\t<p>Test 3</p>\n</html>");
}; };
const auto test18 = []() { const auto test18 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_EMPTY, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_EMPTY, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
REQUIRE(section.get() == "<p>Test 1</p><p>Test 2</p><p>Test 3</p>"); REQUIRE(section.get() == "<p>Test 1</p><p>Test 2</p><p>Test 3</p>");
}; };
const auto test19 = []() { const auto test19 = []() {
docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {});
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); section.push_back(docpp::HTML::Element("p", {}, "Test 1"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); section.push_back(docpp::HTML::Element("p", {}, "Test 2"));
section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); section.push_back(docpp::HTML::Element("p", {}, "Test 3"));
REQUIRE(section.front().get() == "<p>Test 1</p>"); REQUIRE(section.front().get() == "<p>Test 1</p>");
REQUIRE(section.back().get() == "<p>Test 3</p>"); REQUIRE(section.back().get() == "<p>Test 3</p>");
}; };
const auto test20 = []() { const auto test20 = []() {
docpp::HTML::HTMLProperties prop{}; docpp::HTML::Properties prop{};
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("id", "test_id"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("id", "test_id")));
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("class", "class1 class2 class3"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("class", "class1 class2 class3")));
prop.push_back(docpp::HTML::HTMLProperty(std::pair<std::string, std::string>("style", "color: red; font-size: 16px; font-family: Arial;"))); prop.push_back(docpp::HTML::Property(std::pair<std::string, std::string>("style", "color: red; font-size: 16px; font-family: Arial;")));
for (const docpp::HTML::HTMLProperty& p : prop) { for (const docpp::HTML::Property& p : prop) {
REQUIRE(p.getKey() == "id"); REQUIRE(p.getKey() == "id");
REQUIRE(p.getValue() == "test_id"); REQUIRE(p.getValue() == "test_id");
break; break;
} }
for (docpp::HTML::HTMLProperties::iterator it = ++prop.begin(); it != prop.end(); ++it) { for (docpp::HTML::Properties::iterator it = ++prop.begin(); it != prop.end(); ++it) {
REQUIRE(it->getKey() == "class"); REQUIRE(it->getKey() == "class");
REQUIRE(it->getValue() == "class1 class2 class3"); REQUIRE(it->getValue() == "class1 class2 class3");
break; break;
@ -338,30 +338,30 @@ SCENARIO("Test HTML", "[HTML]") {
}; };
const auto test21 = []() { const auto test21 = []() {
docpp::HTML::HTMLSection sect{}; docpp::HTML::Section sect{};
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); sect.push_back(docpp::HTML::Element("p", {}, "Test 1"));
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); sect.push_back(docpp::HTML::Element("p", {}, "Test 2"));
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); sect.push_back(docpp::HTML::Element("p", {}, "Test 3"));
for (const docpp::HTML::HTMLElement& elem : sect) { for (const docpp::HTML::Element& elem : sect) {
REQUIRE(elem.get() == "<p>Test 1</p>"); REQUIRE(elem.get() == "<p>Test 1</p>");
break; break;
} }
for (docpp::HTML::HTMLSection::iterator it = ++sect.begin(); it != sect.end(); ++it) { for (docpp::HTML::Section::iterator it = ++sect.begin(); it != sect.end(); ++it) {
docpp::HTML::HTMLElement elem = *it; docpp::HTML::Element elem = *it;
REQUIRE(elem.get() == "<p>Test 2</p>"); REQUIRE(elem.get() == "<p>Test 2</p>");
break; break;
} }
}; };
const auto test22 = []() { const auto test22 = []() {
docpp::HTML::HTMLSection sect{}; docpp::HTML::Section sect{};
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 1")); sect.push_back(docpp::HTML::Element("p", {}, "Test 1"));
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); sect.push_back(docpp::HTML::Element("p", {}, "Test 2"));
sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); sect.push_back(docpp::HTML::Element("p", {}, "Test 3"));
bool caught{false}; bool caught{false};
try { try {