From 35a15651ca72a91fc16bde8144f8620e789e7b50 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 12 May 2024 20:18:06 +0200 Subject: [PATCH] Rename the different classes. I felt it was too verbose. --- examples/biteme.lol.cpp | 32 ++-- examples/hello-world.cpp | 44 ++--- include/docpp.hpp | 356 ++++++++++++++++++++------------------- src/docpp.cpp | 290 +++++++++++++++---------------- tests/test.cpp | 246 +++++++++++++-------------- 5 files changed, 491 insertions(+), 477 deletions(-) diff --git a/examples/biteme.lol.cpp b/examples/biteme.lol.cpp index 7f1da40..220b1ac 100644 --- a/examples/biteme.lol.cpp +++ b/examples/biteme.lol.cpp @@ -11,13 +11,13 @@ #include int main() { - docpp::HTML::HTMLSection html(docpp::HTML::SECTION_HTML, {}); + docpp::HTML::Section html(docpp::HTML::SECTION_HTML, {}); 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", { {"display", "flex"}, {"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", { {"width", "50vw"}, } @@ -37,27 +37,27 @@ int main() { 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::HTMLProperty("color", "red")}, "o"}); - div.push_back({"font", {docpp::HTML::HTMLProperty("color", "yellow")}, "o"}); - div.push_back({"font", {docpp::HTML::HTMLProperty("color", "blue")}, "g"}); - div.push_back({"font", {docpp::HTML::HTMLProperty("color", "green")}, "l"}); - div.push_back({"font", {docpp::HTML::HTMLProperty("color", "red")}, "e"}); + div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "G"}); + div.push_back({"font", {docpp::HTML::Property("color", "red")}, "o"}); + div.push_back({"font", {docpp::HTML::Property("color", "yellow")}, "o"}); + div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "g"}); + div.push_back({"font", {docpp::HTML::Property("color", "green")}, "l"}); + div.push_back({"font", {docpp::HTML::Property("color", "red")}, "e"}); html.push_back(div); - docpp::HTML::HTMLSection div2{docpp::HTML::SECTION_DIV, {docpp::HTML::HTMLProperty("align", "center")}}; - docpp::HTML::HTMLSection form{"form", {{docpp::HTML::HTMLProperty("action", "https://google.com/search"), docpp::HTML::HTMLProperty("method", "get")}}}; + docpp::HTML::Section div2{docpp::HTML::SECTION_DIV, {docpp::HTML::Property("align", "center")}}; + 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::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", "text"), docpp::HTML::Property("name", "q")}), "", 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); html.push_back(div2); - docpp::HTML::HTMLDocument doc{html}; + docpp::HTML::Document doc{html}; std::ofstream file("biteme.lol.html"); diff --git a/examples/hello-world.cpp b/examples/hello-world.cpp index 951fad0..a4f5cf9 100644 --- a/examples/hello-world.cpp +++ b/examples/hello-world.cpp @@ -12,18 +12,18 @@ 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. * 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(). */ - docpp::HTML::HTMLDocument doc{}; + docpp::HTML::Document doc{}; /* 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 * 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 - * attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty HTMLElementAttributes object. + * 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 ElementAttributes object. * 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, @@ -32,16 +32,16 @@ int main() { * * To get the section as an std::string object, call section.get(). */ - docpp::HTML::HTMLSection htmlSection(docpp::HTML::SECTION_HTML, {}); // - docpp::HTML::HTMLSection headSection(docpp::HTML::SECTION_HEAD, {}); // - docpp::HTML::HTMLSection bodySection(docpp::HTML::SECTION_BODY, {}); // - docpp::HTML::HTMLSection footerSection(docpp::HTML::SECTION_FOOTER, {}); //
+ docpp::HTML::Section htmlSection(docpp::HTML::SECTION_HTML, {}); // + docpp::HTML::Section headSection(docpp::HTML::SECTION_HEAD, {}); // + docpp::HTML::Section bodySection(docpp::HTML::SECTION_BODY, {}); // + docpp::HTML::Section footerSection(docpp::HTML::SECTION_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. * 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 - * attribute name and an attribute value. If you don't want to specify any attributes, you can pass an empty HTMLElementAttributes object. + * 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 ElementAttributes object. * 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. @@ -57,45 +57,45 @@ int main() { * * To get the element as an std::string object, call element.get(). */ - docpp::HTML::HTMLElement titleElement("title", {}, "Hello world document"); // Hello world document + docpp::HTML::Element titleElement("title", {}, "Hello world document"); // Hello world document /* Add the title and meta elements to the head section. */ 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. - * 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. */ - docpp::CSS::CSSStylesheet stylesheet{}; + docpp::CSS::Stylesheet stylesheet{}; /* 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 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. * * 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. */ 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; } - headSection.push_back(docpp::HTML::HTMLElement("style", {}, css)); // + headSection.push_back(docpp::HTML::Element("style", {}, css)); // /* Add a paragraph element to the footer section. */ - footerSection.push_back(docpp::HTML::HTMLElement("p", {}, "This is the footer.")); //

This is the footer.

+ footerSection.push_back(docpp::HTML::Element("p", {}, "This is the footer.")); //

This is the footer.

- docpp::HTML::HTMLSection divSection(docpp::HTML::SECTION_DIV, {{docpp::HTML::HTMLProperty("id", "main")}}); //
+ docpp::HTML::Section divSection(docpp::HTML::SECTION_DIV, {{docpp::HTML::Property("id", "main")}}); //
/* Add a header element and a paragraph element to the div section. */ - divSection.push_back(docpp::HTML::HTMLElement("h1", {}, "Hello world!")); //

Hello world!

- divSection.push_back(docpp::HTML::HTMLElement("p", {}, "This is a paragraph.")); //

This is a paragraph.

+ divSection.push_back(docpp::HTML::Element("h1", {}, "Hello world!")); //

Hello world!

+ divSection.push_back(docpp::HTML::Element("p", {}, "This is a paragraph.")); //

This is a paragraph.

/* Add the div section to the body section. */ bodySection.push_back(divSection); diff --git a/include/docpp.hpp b/include/docpp.hpp index 5b8a54c..9f5b59c 100644 --- a/include/docpp.hpp +++ b/include/docpp.hpp @@ -74,7 +74,7 @@ namespace docpp { /** * @brief A class to represent an HTML property */ - class HTMLProperty { + class Property { private: std::pair property{}; protected: @@ -85,17 +85,17 @@ namespace docpp { 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 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 */ - HTMLProperty(const std::pair& property); - HTMLProperty() = default; + Property(const std::pair& property); + Property() = default; /** * @brief Get the key of the property @@ -129,18 +129,20 @@ namespace docpp { void set(const std::pair& property); }; + using HTMLProperty = Property; + /** * @brief A class to represent the properties of an HTML element */ - class HTMLProperties { + class Properties { private: - std::vector properties{}; + std::vector properties{}; protected: public: - using iterator = std::vector::iterator; - using const_iterator = std::vector::const_iterator; - using reverse_iterator = std::vector::reverse_iterator; - using const_reverse_iterator = std::vector::const_reverse_iterator; + using iterator = std::vector::iterator; + using const_iterator = std::vector::const_iterator; + using reverse_iterator = std::vector::reverse_iterator; + using const_reverse_iterator = std::vector::const_reverse_iterator; /** * @brief Return an iterator to the beginning. @@ -190,26 +192,26 @@ namespace docpp { /** * @brief Get the properties of the element - * @return std::vector The properties of the element + * @return std::vector The properties of the element */ - std::vector getProperties() const; + std::vector getProperties() const; /** * @brief Set the properties of the element * @param properties The properties to set */ - void set(const std::vector& properties); + void set(const std::vector& properties); /** * @brief Get the property at an index * @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 * @param index The index to insert the property * @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 * @param index The index of the property to erase @@ -220,7 +222,7 @@ namespace docpp { * @param property The property to find * @return int The index of the property */ - int find(const HTMLProperty& property); + int find(const Property& property); /** * @brief Find a property in the element * @param str The property to find @@ -238,17 +240,17 @@ namespace docpp { * @param property1 The first 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 - * @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 - * @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 * @return int The size of the element @@ -258,43 +260,43 @@ namespace docpp { * @brief Prepend a property to the element * @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 * @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 */ - HTMLProperties(const std::vector& properties); + Properties(const std::vector& properties); /** - * @brief Construct a new HTMLProperties object + * @brief Construct a new Properties object * @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; - HTMLProperties operator=(const HTMLProperties& properties); - HTMLProperties operator=(const std::vector& properties); - HTMLProperties operator=(const HTMLProperty& property); - void operator+=(const HTMLProperty& property); + Properties() = default; + Properties operator=(const Properties& properties); + Properties operator=(const std::vector& properties); + Properties operator=(const Property& property); + void operator+=(const Property& property); }; - using HTMLElementProperties = HTMLProperties; + using HTMLElementProperties = Properties; /** * @brief A class to represent an HTML element */ - class HTMLElement { + class Element { private: std::string tag{}; std::string data{}; int type{TYPE_NON_SELF_CLOSING}; - HTMLProperties properties{}; + Properties properties{}; protected: public: /** @@ -303,23 +305,23 @@ namespace docpp { 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 properties The properties 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 * @param tag The tag of the element * @param id The id 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. @@ -338,25 +340,27 @@ namespace docpp { * @return std::string The data of the element */ std::string getData() const; - HTMLElement operator=(const HTMLElement& element); + Element operator=(const Element& element); void operator+=(const std::string& data); }; + using HTMLElement = Element; + /** * @brief A class to represent an HTML section (head, body, etc.) */ - class HTMLSection { + class Section { private: int index{}; std::string tag{}; - HTMLProperties properties{}; + Properties properties{}; - std::map elements{}; - std::unordered_map sections{}; + std::map elements{}; + std::unordered_map sections{}; protected: public: /** - * @brief A class to represent an iterator for the HTMLSection class + * @brief A class to represent an iterator for the Section class */ template class sect_iterator { @@ -365,15 +369,15 @@ namespace docpp { public: sect_iterator(const T& element) : element(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; } }; - using iterator = sect_iterator::iterator>; - using const_iterator = sect_iterator::const_iterator>; - using reverse_iterator = sect_iterator::reverse_iterator>; - using const_reverse_iterator = sect_iterator::const_reverse_iterator>; + using iterator = sect_iterator::iterator>; + using const_iterator = sect_iterator::const_iterator>; + using reverse_iterator = sect_iterator::reverse_iterator>; + using const_reverse_iterator = sect_iterator::const_reverse_iterator>; iterator begin() { return iterator(elements.begin()); } iterator end() { return iterator(elements.end()); } @@ -393,34 +397,34 @@ namespace docpp { * @brief Prepend an element to the section * @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 * @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 * @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 * @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() * @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() * @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. * @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. * @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. * @param element The element to erase */ - void erase(const HTMLElement& element); + void erase(const Element& element); /** * @brief Find an element in the section * @param element The element to find * @return int The index of the element */ - int find(const HTMLElement& element); + int find(const Element& element); /** * @brief Find a section in the section * @param section The section to find * @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 * @param str The element or section to find @@ -459,33 +463,33 @@ namespace docpp { * @param index The index to insert the element * @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 * @param index The index to insert the section * @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 - * @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 - * @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 - * @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 - * @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 * @return int The size of the section @@ -493,35 +497,35 @@ namespace docpp { int size() const; /** - * @brief Construct a new HTMLSection object + * @brief Construct a new Section object * @param tag The tag 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 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 * @param tag The tag of the section * @param id The id 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 * @param tag The tag of the section * @param id The id 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 * @param index1 The index of the first element @@ -533,23 +537,23 @@ namespace docpp { * @param element1 The first 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 * @param index1 The index of the first 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 - * @return std::vector The elements of the section + * @return std::vector The elements of the section */ - std::vector getHTMLElements() const; + std::vector getElements() const; /** * @brief Get the sections of the section - * @return std::vector The sections of the section + * @return std::vector
The sections of the section */ - std::vector getHTMLSections() const; + std::vector
getSections() const; /** * @brief Dump the entire section. @@ -557,19 +561,21 @@ namespace docpp { */ std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; - HTMLSection operator=(const HTMLSection& section); - void operator+=(const HTMLElement& element); - void operator+=(const HTMLSection& section); - HTMLElement operator[](const int& index) const; + Section operator=(const Section& section); + void operator+=(const Element& element); + void operator+=(const Section& section); + Element operator[](const int& index) const; }; + using HTMLSection = Section; + /** * @brief A class to represent an HTML document */ - class HTMLDocument { + class Document { private: std::string doctype{""}; - HTMLSection document{}; + Section document{}; protected: public: /** @@ -586,9 +592,9 @@ namespace docpp { /** * @brief Get the section - * @return HTMLSection The section + * @return Section The section */ - HTMLSection& getSection(); + Section& getSection(); /** * @brief Get the doctype of the document @@ -600,25 +606,27 @@ namespace docpp { * @brief Set the document * @param document The document to set */ - void set(const HTMLSection& document); + void set(const Section& document); /** * @brief Set the doctype of the document * @param doctype The doctype to set */ 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 */ - HTMLDocument(const HTMLSection& document, const std::string& doctype = ""); + Document(const Section& document, const std::string& doctype = ""); - HTMLDocument operator=(const HTMLDocument& document); - HTMLDocument operator=(const HTMLSection& section); + Document operator=(const Document& document); + Document operator=(const Section& section); }; + + using HTMLDocument = Document; } // namespace HTML /** @@ -634,7 +642,7 @@ namespace docpp { /** * @brief A class to represent a CSS property */ - class CSSProperty { + class Property { private: std::pair property{}; protected: @@ -645,17 +653,17 @@ namespace docpp { 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 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 */ - CSSProperty(const std::pair& property); - CSSProperty() = default; + Property(const std::pair& property); + Property() = default; /** * @brief Get the key of the property @@ -694,19 +702,21 @@ namespace docpp { */ void set(const std::string& key, const std::string& value); - CSSProperty operator=(const CSSProperty& property); - CSSProperty operator=(const std::pair& property); + Property operator=(const Property& property); + Property operator=(const std::pair& property); }; - class CSSElement { + using CSSProperty = Property; + + class Element { private: - std::pair> element{}; + std::pair> element{}; protected: public: - using iterator = std::vector::iterator; - using const_iterator = std::vector::const_iterator; - using reverse_iterator = std::vector::reverse_iterator; - using const_reverse_iterator = std::vector::const_reverse_iterator; + using iterator = std::vector::iterator; + using const_iterator = std::vector::const_iterator; + using reverse_iterator = std::vector::reverse_iterator; + using const_reverse_iterator = std::vector::const_reverse_iterator; /** * @brief Return an iterator to the beginning. @@ -755,34 +765,34 @@ namespace docpp { 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 properties The properties of the element */ - CSSElement(const std::string& tag, const std::vector& properties); + Element(const std::string& tag, const std::vector& properties); /** - * @brief Construct a new CSSElement object + * @brief Construct a new Element object * @param element The element to set */ - CSSElement(const std::pair>& element); - CSSElement() = default; + Element(const std::pair>& element); + Element() = default; /** * @brief Prepend a property to the element * @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 * @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 * @param index The index to insert the property * @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 * @param index The index of the property to erase @@ -793,13 +803,13 @@ namespace docpp { * @param property The property to find * @return int The index of the property */ - int find(const CSSProperty& property); + int find(const Property& property); /** * @brief Get the property at an index * @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 * @param str The property to find @@ -817,17 +827,17 @@ namespace docpp { * @param property1 The first 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 - * @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 - * @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 * @return int The size of the element @@ -837,15 +847,15 @@ namespace docpp { * @brief Set the properties of the element * @param properties The properties to set */ - void set(const std::string& tag, const std::vector& properties); + void set(const std::string& tag, const std::vector& properties); /** * @brief Set the properties of the element * @param element The element to set */ - void set(const std::pair>& element); + void set(const std::pair>& element); /** * @brief Get the element - * @return std::pair> The element + * @return std::pair> The element */ std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; /** @@ -855,28 +865,30 @@ namespace docpp { std::string getTag() const; /** * @brief Get the properties of the element - * @return std::vector The properties of the element + * @return std::vector The properties of the element */ - std::vector getProperties() const; + std::vector getProperties() const; - CSSElement operator=(const CSSElement& element); - CSSElement operator=(const std::pair>& element); - void operator+=(const CSSProperty& property); - CSSProperty operator[](const int& index) const; + Element operator=(const Element& element); + Element operator=(const std::pair>& element); + void operator+=(const Property& property); + Property operator[](const int& index) const; }; + using CSSElement = Element; + /** * @brief A class to represent a CSS stylesheet */ - class CSSStylesheet { + class Stylesheet { private: - std::vector elements{}; + std::vector elements{}; protected: public: - using iterator = std::vector::iterator; - using const_iterator = std::vector::const_iterator; - using reverse_iterator = std::vector::reverse_iterator; - using const_reverse_iterator = std::vector::const_reverse_iterator; + using iterator = std::vector::iterator; + using const_iterator = std::vector::const_iterator; + using reverse_iterator = std::vector::reverse_iterator; + using const_reverse_iterator = std::vector::const_reverse_iterator; /** * @brief Return an iterator to the beginning. @@ -925,28 +937,28 @@ namespace docpp { static const int npos = -1; /** - * @brief Construct a new CSSStylesheet object + * @brief Construct a new Stylesheet object * @param elements The elements to set */ - CSSStylesheet(const std::vector& elements); - CSSStylesheet() = default; + Stylesheet(const std::vector& elements); + Stylesheet() = default; /** * @brief Prepend an element to the stylesheet * @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 * @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 * @param index The index to insert the element * @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. * @param index The index of the element to erase @@ -957,7 +969,7 @@ namespace docpp { * @param element The element to find * @return int The index of the element */ - int find(const CSSElement& element); + int find(const Element& element); /** * @brief Find an element in the stylesheet * @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 * @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 * @return int The size of the stylesheet @@ -977,14 +989,14 @@ namespace docpp { int size() const; /** * @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 - * @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 * @param index1 The index of the first element @@ -996,26 +1008,28 @@ namespace docpp { * @param element1 The first 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 * @param elements The elements to set */ - void set(const std::vector& elements); + void set(const std::vector& elements); /** * @brief Get the elements of the stylesheet - * @return std::vector The elements of the stylesheet + * @return std::vector The elements of the stylesheet */ - std::vector getElements() const; + std::vector getElements() const; /** * @brief Get the stylesheet * @return std::string The stylesheet */ std::string get(const int formatting = FORMATTING_NONE, const int tabc = 0) const; - CSSStylesheet operator=(const CSSStylesheet& stylesheet); - void operator+=(const CSSElement& element); - CSSElement operator[](const int& index) const; + Stylesheet operator=(const Stylesheet& stylesheet); + void operator+=(const Element& element); + Element operator[](const int& index) const; }; + + using CSSStylesheet = Stylesheet; } } diff --git a/src/docpp.cpp b/src/docpp.cpp index fc1fa12..f01db88 100644 --- a/src/docpp.cpp +++ b/src/docpp.cpp @@ -16,71 +16,71 @@ #include #include -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->setValue(value); } -docpp::HTML::HTMLProperty::HTMLProperty(const std::pair& property) { +docpp::HTML::Property::Property(const std::pair& property) { this->set(property); } -std::string docpp::HTML::HTMLProperty::getKey() const { +std::string docpp::HTML::Property::getKey() const { return this->property.first; } -std::string docpp::HTML::HTMLProperty::getValue() const { +std::string docpp::HTML::Property::getValue() const { return this->property.second; } -std::pair docpp::HTML::HTMLProperty::get() const { +std::pair docpp::HTML::Property::get() const { 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; } -void docpp::HTML::HTMLProperty::setValue(const std::string& value) { +void docpp::HTML::Property::setValue(const std::string& value) { this->property.second = value; } -void docpp::HTML::HTMLProperty::set(const std::pair& property) { +void docpp::HTML::Property::set(const std::pair& property) { this->property = property; } -docpp::HTML::HTMLProperties::HTMLProperties(const std::vector& properties) { +docpp::HTML::Properties::Properties(const std::vector& 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); } -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}; 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()); return *this; } -docpp::HTML::HTMLProperties docpp::HTML::HTMLProperties::operator=(const std::vector& properties) { +docpp::HTML::Properties docpp::HTML::Properties::operator=(const std::vector& properties) { this->set(properties); 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); } -std::vector docpp::HTML::HTMLProperties::getProperties() const { +std::vector docpp::HTML::Properties::getProperties() const { 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()) { 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); } -void docpp::HTML::HTMLProperties::set(const std::vector& properties) { +void docpp::HTML::Properties::set(const std::vector& 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()) { 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); } -void docpp::HTML::HTMLProperties::erase(const int index) { +void docpp::HTML::Properties::erase(const int index) { if (index < 0 || index >= this->properties.size()) { 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); } -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); } -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); } -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++) { if (!this->properties.at(i).getKey().compare(property.getKey())) { 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++) { if (!this->properties.at(i).getKey().compare(str) || !this->properties.at(i).getValue().compare(str)) { 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(); } -docpp::HTML::HTMLProperty docpp::HTML::HTMLProperties::back() const { +docpp::HTML::Property docpp::HTML::Properties::back() const { return this->properties.back(); } -int docpp::HTML::HTMLProperties::size() const { +int docpp::HTML::Properties::size() const { 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()) { 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]); } -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)); } -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); } -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); return *this; } -void docpp::HTML::HTMLElement::operator+=(const std::string& data) { +void docpp::HTML::Element::operator+=(const std::string& 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->data = data; this->properties = properties; 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{}; 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); } -std::string docpp::HTML::HTMLElement::getTag() const { +std::string docpp::HTML::Element::getTag() const { return this->tag; } -std::string docpp::HTML::HTMLElement::getData() const { +std::string docpp::HTML::Element::getData() const { 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->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->properties = section.properties; this->elements = section.elements; @@ -258,28 +258,28 @@ docpp::HTML::HTMLSection docpp::HTML::HTMLSection::operator=(const docpp::HTML:: 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); } -void docpp::HTML::HTMLSection::operator+=(const docpp::HTML::HTMLSection& section) { +void docpp::HTML::Section::operator+=(const docpp::HTML::Section& 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); } -docpp::HTML::HTMLSection::HTMLSection(const int tag, const HTMLProperties& properties) { +docpp::HTML::Section::Section(const int tag, const Properties& 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->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) { this->tag = "div"; } 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; } -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--) { this->elements[i] = this->elements.at(i - 1); } @@ -304,7 +304,7 @@ void docpp::HTML::HTMLSection::push_front(const HTMLElement& element) { 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--) { this->sections.at(i) = this->sections.at(i - 1); } @@ -313,15 +313,15 @@ void docpp::HTML::HTMLSection::push_front(const HTMLSection& section) { 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; } -void docpp::HTML::HTMLSection::push_back(const HTMLSection& section) { +void docpp::HTML::Section::push_back(const Section& 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}; 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++) { - const auto it = this->getHTMLSections().at(i); + const auto it = this->getSections().at(i); if (it.get() == section.get()) { this->erase(i); @@ -350,9 +350,9 @@ void docpp::HTML::HTMLSection::erase(const HTMLSection& section) { 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++) { - const auto it = this->getHTMLElements().at(i); + const auto it = this->getElements().at(i); if (it.get() == element.get()) { this->erase(i); @@ -363,7 +363,7 @@ void docpp::HTML::HTMLSection::erase(const HTMLElement& element) { 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()) { throw docpp::invalid_argument("Index already occupied by a section"); } else { @@ -373,12 +373,12 @@ void docpp::HTML::HTMLSection::insert(const int index, const HTMLElement& elemen 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->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()) { 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"); } -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()) { 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"); } -int docpp::HTML::HTMLSection::find(const HTMLElement& element) { +int docpp::HTML::Section::find(const Element& element) { 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()) { 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++) { - const auto it = this->getHTMLSections().at(i); + const auto it = this->getSections().at(i); if (it.get() == section.get()) { return i; } } - return docpp::HTML::HTMLSection::npos; + return docpp::HTML::Section::npos; } -int docpp::HTML::HTMLSection::find(const std::string& str) { - const auto elements = this->getHTMLElements(); +int docpp::HTML::Section::find(const std::string& str) { + const auto elements = this->getElements(); for (int i{0}; i < elements.size(); i++) { 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++) { 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()) { 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"); } -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()) { 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"); } -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()) { 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"); } -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()) { 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"); } -int docpp::HTML::HTMLSection::size() const { +int docpp::HTML::Section::size() const { return this->index; } -std::vector docpp::HTML::HTMLSection::getHTMLElements() const { - std::vector ret{}; +std::vector docpp::HTML::Section::getElements() const { + std::vector ret{}; ret.reserve(this->index); for (int i{0}; i < this->index; i++) { if (this->elements.find(i) != this->elements.end()) { @@ -485,8 +485,8 @@ std::vector docpp::HTML::HTMLSection::getHTMLElements( return std::move(ret); } -std::vector docpp::HTML::HTMLSection::getHTMLSections() const { - std::vector ret{}; +std::vector docpp::HTML::Section::getSections() const { + std::vector ret{}; ret.reserve(this->index); for (int i{0}; i < this->index; i++) { @@ -498,7 +498,7 @@ std::vector docpp::HTML::HTMLSection::getHTMLSections( 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{}; int tabcount{tabc}; @@ -556,7 +556,7 @@ std::string docpp::HTML::HTMLSection::get(const int formatting, const int tabc) 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()) { std::swap(this->elements[index1], this->elements[index2]); } 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)); } -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)); } -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); } -docpp::HTML::HTMLSection& docpp::HTML::HTMLDocument::getSection() { +docpp::HTML::Section& docpp::HTML::Document::getSection() { 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; } -void docpp::HTML::HTMLDocument::setDoctype(const std::string& doctype) { +void docpp::HTML::Document::setDoctype(const std::string& 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->setDoctype(document.getDoctype()); 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); 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->setDoctype(doctype); } -std::string docpp::HTML::HTMLDocument::getDoctype() const { +std::string docpp::HTML::Document::getDoctype() const { 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); } -docpp::CSS::CSSProperty::CSSProperty(const std::pair& property) { +docpp::CSS::Property::Property(const std::pair& property) { this->set(property); } -std::string docpp::CSS::CSSProperty::getKey() const { +std::string docpp::CSS::Property::getKey() const { return this->property.first; } -std::string docpp::CSS::CSSProperty::getValue() const { +std::string docpp::CSS::Property::getValue() const { return this->property.second; } -std::pair docpp::CSS::CSSProperty::get() const { +std::pair docpp::CSS::Property::get() const { 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; } -void docpp::CSS::CSSProperty::setValue(const std::string& value) { +void docpp::CSS::Property::setValue(const std::string& value) { this->property.second = value; } -void docpp::CSS::CSSProperty::set(const std::pair& property) { +void docpp::CSS::Property::set(const std::pair& 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); } -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()); return *this; } -docpp::CSS::CSSProperty docpp::CSS::CSSProperty::operator=(const std::pair& property) { +docpp::CSS::Property docpp::CSS::Property::operator=(const std::pair& property) { this->set(property); return *this; } -docpp::CSS::CSSElement::CSSElement(const std::string& tag, const std::vector& properties) { +docpp::CSS::Element::Element(const std::string& tag, const std::vector& properties) { this->set(tag, properties); } -docpp::CSS::CSSElement::CSSElement(const std::pair>& element) { +docpp::CSS::Element::Element(const std::pair>& 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()}); return *this; } -void docpp::CSS::CSSElement::operator+=(const CSSProperty& property) { +void docpp::CSS::Element::operator+=(const Property& 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); } -void docpp::CSS::CSSElement::set(const std::string& tag, const std::vector& properties) { +void docpp::CSS::Element::set(const std::string& tag, const std::vector& properties) { this->element.first = tag; this->element.second = properties; } -void docpp::CSS::CSSElement::set(const std::pair>& element) { +void docpp::CSS::Element::set(const std::pair>& 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); } -void docpp::CSS::CSSElement::push_back(const CSSProperty& property) { +void docpp::CSS::Element::push_back(const Property& 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()) { 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); } -void docpp::CSS::CSSElement::erase(const int index) { +void docpp::CSS::Element::erase(const int index) { if (index < 0 || index >= this->element.second.size()) { 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); } -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()) { 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); } -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++) { if (this->element.second.at(i).get() == property.get()) { 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++) { if (!this->element.second.at(i).getKey().compare(str) || !this->element.second.at(i).getValue().compare(str)) { 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(); } -docpp::CSS::CSSProperty docpp::CSS::CSSElement::back() const { +docpp::CSS::Property docpp::CSS::Element::back() const { return this->element.second.back(); } -int docpp::CSS::CSSElement::size() const { +int docpp::CSS::Element::size() const { 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()) { 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]); } -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)); } -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{}; 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); } -std::string docpp::CSS::CSSElement::getTag() const { +std::string docpp::CSS::Element::getTag() const { return this->element.first; } -std::vector docpp::CSS::CSSElement::getProperties() const { +std::vector docpp::CSS::Element::getProperties() const { return this->element.second; } -docpp::CSS::CSSStylesheet::CSSStylesheet(const std::vector& elements) { +docpp::CSS::Stylesheet::Stylesheet(const std::vector& elements) { this->set(elements); } -void docpp::CSS::CSSStylesheet::set(const std::vector& elements) { +void docpp::CSS::Stylesheet::set(const std::vector& 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); } -void docpp::CSS::CSSStylesheet::push_back(const CSSElement& element) { +void docpp::CSS::Stylesheet::push_back(const Element& 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()) { 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); } -void docpp::CSS::CSSStylesheet::erase(const int index) { +void docpp::CSS::Stylesheet::erase(const int index) { if (index < 0 || index >= this->elements.size()) { 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); } -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()); return *this; } -void docpp::CSS::CSSStylesheet::operator+=(const CSSElement& element) { +void docpp::CSS::Stylesheet::operator+=(const Element& 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); } -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()) { 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); } -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++) { if (this->elements.at(i).get() == element.get()) { 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++) { if (!this->elements.at(i).get().compare(str) || !this->elements.at(i).getTag().compare(str)) { 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(); } -docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::front() const { +docpp::CSS::Element docpp::CSS::Stylesheet::front() const { return this->elements.front(); } -docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::back() const { +docpp::CSS::Element docpp::CSS::Stylesheet::back() const { 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()) { 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]); } -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)); } -std::vector docpp::CSS::CSSStylesheet::getElements() const { +std::vector docpp::CSS::Stylesheet::getElements() const { 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{}; for (const auto& it : this->elements) { diff --git a/tests/test.cpp b/tests/test.cpp index a5fd8e2..1f59eff 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -8,29 +8,29 @@ */ SCENARIO("Test HTML", "[HTML]") { const auto test1 = []() { - docpp::HTML::HTMLDocument doc{}; - docpp::HTML::HTMLSection html(docpp::HTML::SECTION_HTML, {}); + docpp::HTML::Document doc{}; + docpp::HTML::Section html(docpp::HTML::SECTION_HTML, {}); - docpp::HTML::HTMLSection head(docpp::HTML::SECTION_HEAD, {}); - docpp::HTML::HTMLSection body(docpp::HTML::SECTION_BODY, {}); - docpp::HTML::HTMLSection div(docpp::HTML::SECTION_DIV, {}); - docpp::HTML::HTMLSection footer(docpp::HTML::SECTION_FOOTER, {}); + docpp::HTML::Section head(docpp::HTML::SECTION_HEAD, {}); + docpp::HTML::Section body(docpp::HTML::SECTION_BODY, {}); + docpp::HTML::Section div(docpp::HTML::SECTION_DIV, {}); + docpp::HTML::Section footer(docpp::HTML::SECTION_FOOTER, {}); - head.push_back(docpp::HTML::HTMLElement("title", {}, "Test Title")); - body.push_back(docpp::HTML::HTMLElement("h1", {}, "Test Header")); - body.push_back(docpp::HTML::HTMLElement("p", {}, "Test Paragraph")); + head.push_back(docpp::HTML::Element("title", {}, "Test Title")); + body.push_back(docpp::HTML::Element("h1", {}, "Test Header")); + body.push_back(docpp::HTML::Element("p", {}, "Test Paragraph")); - docpp::HTML::HTMLProperties prop{}; - prop.push_back(docpp::HTML::HTMLProperty(std::pair("id", "test_id"))); + docpp::HTML::Properties prop{}; + prop.push_back(docpp::HTML::Property(std::pair("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); - prop.push_back(docpp::HTML::HTMLProperty(std::pair("class", "class1 class2 class3"))); + prop.push_back(docpp::HTML::Property(std::pair("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(body); @@ -45,40 +45,40 @@ SCENARIO("Test HTML", "[HTML]") { }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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() == "

Test 1

Test 3

"); REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "\n

Test 1

\n

Test 3

\n"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + section.push_back(docpp::HTML::Element("p", {}, "Test 3")); - int pos = section.find(docpp::HTML::HTMLElement("p", {}, "Test 2")); - section.insert(pos, docpp::HTML::HTMLElement("p", {}, "Test 2.5")); + int pos = section.find(docpp::HTML::Element("p", {}, "Test 2")); + section.insert(pos, docpp::HTML::Element("p", {}, "Test 2.5")); REQUIRE(section.get() == "

Test 1

Test 2.5

Test 3

"); REQUIRE(section.get(docpp::HTML::FORMATTING_NEWLINE) == "\n

Test 1

\n

Test 2.5

\n

Test 3

\n"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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); @@ -87,19 +87,19 @@ SCENARIO("Test HTML", "[HTML]") { }; const auto test5 = []() { - docpp::HTML::HTMLSection section = docpp::HTML::HTMLSection(docpp::HTML::SECTION_HTML, {}); - docpp::HTML::HTMLSection subsection(docpp::HTML::SECTION_DIV, {}); + docpp::HTML::Section section = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {}); + 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, {}); - subsection2.push_back(docpp::HTML::HTMLElement("p", {}, "Test 2")); + docpp::HTML::Section subsection2(docpp::HTML::SECTION_DIV, {}); + subsection2.push_back(docpp::HTML::Element("p", {}, "Test 2")); subsection.push_back(subsection2); section.push_back(subsection); - docpp::HTML::HTMLDocument doc{}; + docpp::HTML::Document doc{}; doc.set(section); REQUIRE(doc.get() == "

Test 1

Test 2

"); @@ -107,8 +107,8 @@ SCENARIO("Test HTML", "[HTML]") { }; const auto test6 = []() { - docpp::CSS::CSSStylesheet css{}; - docpp::CSS::CSSElement element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; + docpp::CSS::Stylesheet css{}; + docpp::CSS::Element element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; css.push_back(element); @@ -117,9 +117,9 @@ SCENARIO("Test HTML", "[HTML]") { }; const auto test7 = []() { - docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; - docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; - docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; + docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{}; + docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; + docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; css.push_back(element); css.push_front(element2); @@ -128,9 +128,9 @@ SCENARIO("Test HTML", "[HTML]") { }; const auto test8 = []() { - docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; - docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; - docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; + docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{}; + docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; + docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; css.push_back(element); css.push_front(element2); @@ -141,9 +141,9 @@ SCENARIO("Test HTML", "[HTML]") { }; const auto test9 = []() { - docpp::CSS::CSSStylesheet css = docpp::CSS::CSSStylesheet{}; - docpp::CSS::CSSElement element = docpp::CSS::CSSElement{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; - docpp::CSS::CSSElement element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; + docpp::CSS::Stylesheet css = docpp::CSS::Stylesheet{}; + docpp::CSS::Element element = docpp::CSS::Element{"p", {{"color", "red"}, {"font-size", "16px"}, {"font-family", "Arial"}}}; + docpp::CSS::Element element2{"div", {{"color", "blue"}, {"font-size", "12px"}, {"font-family", "Arial"}}}; css.push_back(element); 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;}"); - 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;}"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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() == "

Test 1

Test 3

Test 2

"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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() == "

Test 1

Test 3

Test 2

"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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() == "

Test 0

Test 1

Test 2

Test 3

"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 4")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 5")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 6")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + section.push_back(docpp::HTML::Element("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 4")); + section.push_back(docpp::HTML::Element("p", {}, "Test 5")); + section.push_back(docpp::HTML::Element("p", {}, "Test 6")); const int pos{section.find("

Test 2

")}; - REQUIRE(pos != docpp::HTML::HTMLSection::npos); + REQUIRE(pos != docpp::HTML::Section::npos); const int pos2{section.find("

Test 6

")}; @@ -219,118 +219,118 @@ SCENARIO("Test HTML", "[HTML]") { }; 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"); - REQUIRE(red != docpp::CSS::CSSElement::npos); + REQUIRE(red != docpp::CSS::Element::npos); const int blue = element.find("blue"); - REQUIRE(blue == docpp::CSS::CSSElement::npos); + REQUIRE(blue == docpp::CSS::Element::npos); element.erase(red); 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;}"); }; const auto test15 = []() { - docpp::HTML::HTMLProperties prop{}; + docpp::HTML::Properties prop{}; - prop.push_back(docpp::HTML::HTMLProperty(std::pair("id", "test_id"))); - prop.push_back(docpp::HTML::HTMLProperty(std::pair("class", "class1 class2 class3"))); + prop.push_back(docpp::HTML::Property(std::pair("id", "test_id"))); + prop.push_back(docpp::HTML::Property(std::pair("class", "class1 class2 class3"))); - REQUIRE(docpp::HTML::HTMLElement("p", prop, {}).get() == "

"); + REQUIRE(docpp::HTML::Element("p", prop, {}).get() == "

"); const int pos = prop.find("class"); - REQUIRE(pos != docpp::HTML::HTMLProperties::npos); + REQUIRE(pos != docpp::HTML::Properties::npos); const int pos2 = prop.find("class2"); REQUIRE(prop.at(pos2).getKey() == "class"); 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"); - REQUIRE(pos3 == docpp::HTML::HTMLProperties::npos); + REQUIRE(pos3 == docpp::HTML::Properties::npos); prop.erase(pos); - REQUIRE(docpp::HTML::HTMLElement("p", prop, {}).get() == "

"); + REQUIRE(docpp::HTML::Element("p", prop, {}).get() == "

"); }; 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::HTMLElement("p", {}, "Test 2")); - doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 1")); + doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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::HTMLElement("p", {}, "Test 5")); - doc.getSection().push_back(docpp::HTML::HTMLElement("p", {}, "Test 6")); + doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 4")); + doc.getSection().push_back(docpp::HTML::Element("p", {}, "Test 5")); + 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() == "

Test 4

Test 5

Test 6

Test 7

"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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) == "\n\n\t

Test 1

\n\t

Test 2

\n\t

Test 3

\n"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + section.push_back(docpp::HTML::Element("p", {}, "Test 3")); REQUIRE(section.get() == "

Test 1

Test 2

Test 3

"); }; 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::HTMLElement("p", {}, "Test 2")); - section.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + section.push_back(docpp::HTML::Element("p", {}, "Test 1")); + section.push_back(docpp::HTML::Element("p", {}, "Test 2")); + section.push_back(docpp::HTML::Element("p", {}, "Test 3")); REQUIRE(section.front().get() == "

Test 1

"); REQUIRE(section.back().get() == "

Test 3

"); }; const auto test20 = []() { - docpp::HTML::HTMLProperties prop{}; + docpp::HTML::Properties prop{}; - prop.push_back(docpp::HTML::HTMLProperty(std::pair("id", "test_id"))); - prop.push_back(docpp::HTML::HTMLProperty(std::pair("class", "class1 class2 class3"))); - prop.push_back(docpp::HTML::HTMLProperty(std::pair("style", "color: red; font-size: 16px; font-family: Arial;"))); + prop.push_back(docpp::HTML::Property(std::pair("id", "test_id"))); + prop.push_back(docpp::HTML::Property(std::pair("class", "class1 class2 class3"))); + prop.push_back(docpp::HTML::Property(std::pair("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.getValue() == "test_id"); 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->getValue() == "class1 class2 class3"); break; @@ -338,30 +338,30 @@ SCENARIO("Test HTML", "[HTML]") { }; 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::HTMLElement("p", {}, "Test 2")); - sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + sect.push_back(docpp::HTML::Element("p", {}, "Test 1")); + sect.push_back(docpp::HTML::Element("p", {}, "Test 2")); + 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() == "

Test 1

"); break; } - for (docpp::HTML::HTMLSection::iterator it = ++sect.begin(); it != sect.end(); ++it) { - docpp::HTML::HTMLElement elem = *it; + for (docpp::HTML::Section::iterator it = ++sect.begin(); it != sect.end(); ++it) { + docpp::HTML::Element elem = *it; REQUIRE(elem.get() == "

Test 2

"); break; } }; 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::HTMLElement("p", {}, "Test 2")); - sect.push_back(docpp::HTML::HTMLElement("p", {}, "Test 3")); + sect.push_back(docpp::HTML::Element("p", {}, "Test 1")); + sect.push_back(docpp::HTML::Element("p", {}, "Test 2")); + sect.push_back(docpp::HTML::Element("p", {}, "Test 3")); bool caught{false}; try {