Add Doxygen file, remove old aliases.

This commit is contained in:
Jacob 2024-05-12 21:56:03 +02:00
parent 35a15651ca
commit 2f9c24e8ab
6 changed files with 5623 additions and 146 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.cache .cache
build build
docs/html

2825
docs/Doxyfile Executable file

File diff suppressed because it is too large Load diff

2669
docs/index.css Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,13 +3,6 @@
* Licensed under the LGPL-3.0-or-later license. * Licensed under the LGPL-3.0-or-later license.
* *
* Author: speedie <speedie@speedie.site> * Author: speedie <speedie@speedie.site>
*
* @file docpp.hpp
* @brief Header file for docpp
* @author speedie
* @date 2024
* @copyright GNU Lesser General Public License 3.0
* @version 0.0.1
*/ */
#pragma once #pragma once
@ -79,10 +72,12 @@ namespace docpp {
std::pair<std::string, std::string> property{}; std::pair<std::string, std::string> property{};
protected: protected:
public: public:
using size_type = std::size_t;
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Construct a new Property object * @brief Construct a new Property object
@ -129,8 +124,6 @@ namespace docpp {
void set(const std::pair<std::string, std::string>& property); void set(const std::pair<std::string, std::string>& property);
}; };
using HTMLProperty = Property;
/** /**
* @brief A class to represent the properties of an HTML element * @brief A class to represent the properties of an HTML element
*/ */
@ -139,6 +132,7 @@ namespace docpp {
std::vector<Property> properties{}; std::vector<Property> properties{};
protected: protected:
public: public:
using size_type = std::size_t;
using iterator = std::vector<Property>::iterator; using iterator = std::vector<Property>::iterator;
using const_iterator = std::vector<Property>::const_iterator; using const_iterator = std::vector<Property>::const_iterator;
using reverse_iterator = std::vector<Property>::reverse_iterator; using reverse_iterator = std::vector<Property>::reverse_iterator;
@ -188,7 +182,7 @@ namespace docpp {
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Get the properties of the element * @brief Get the properties of the element
@ -205,36 +199,36 @@ namespace docpp {
* @param index The index of the property * @param index The index of the property
* @return Property The property at the index * @return Property The property at the index
*/ */
Property at(const int index) const; Property at(const size_type index) const;
/** /**
* @brief Insert a property into the element * @brief Insert a property into the element
* @param index The index to insert the property * @param index The index to insert the property
* @param property The property to insert * @param property The property to insert
*/ */
void insert(const int index, const Property& property); void insert(const size_type index, const Property& property);
/** /**
* @brief Erase a property from the element * @brief Erase a property from the element
* @param index The index of the property to erase * @param index The index of the property to erase
*/ */
void erase(const int index); void erase(const size_type index);
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param property The property to find * @param property The property to find
* @return int The index of the property * @return size_type The index of the property
*/ */
int find(const Property& property); size_type find(const Property& property);
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param str The property to find * @param str The property to find
* @return int The index of the property * @return size_type The index of the property
*/ */
int find(const std::string& str); size_type find(const std::string& str);
/** /**
* @brief Swap two properties in the element * @brief Swap two properties in the element
* @param index1 The index of the first property * @param index1 The index of the first property
* @param index2 The index of the second property * @param index2 The index of the second property
*/ */
void swap(const int index1, const int index2); void swap(const size_type index1, const size_type index2);
/** /**
* @brief Swap two properties in the element * @brief Swap two properties in the element
* @param property1 The first property * @param property1 The first property
@ -253,9 +247,9 @@ namespace docpp {
Property back() const; Property back() const;
/** /**
* @brief Get the size of the element * @brief Get the size of the element
* @return int The size of the element * @return size_type The size of the element
*/ */
int size() const; size_type size() const;
/** /**
* @brief Prepend a property to the element * @brief Prepend a property to the element
* @param property The property to add * @param property The property to add
@ -286,8 +280,6 @@ namespace docpp {
void operator+=(const Property& property); void operator+=(const Property& property);
}; };
using HTMLElementProperties = Properties;
/** /**
* @brief A class to represent an HTML element * @brief A class to represent an HTML element
*/ */
@ -299,10 +291,11 @@ namespace docpp {
Properties properties{}; Properties properties{};
protected: protected:
public: public:
using size_type = std::size_t;
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Construct a new Element object * @brief Construct a new Element object
@ -344,21 +337,14 @@ namespace docpp {
void operator+=(const std::string& data); void operator+=(const std::string& data);
}; };
using HTMLElement = Element;
/** /**
* @brief A class to represent an HTML section (head, body, etc.) * @brief A class to represent an HTML section (head, body, etc.)
*/ */
class Section { class Section {
private:
int index{};
std::string tag{};
Properties properties{};
std::map<int, Element> elements{};
std::unordered_map<int, Section> sections{};
protected: protected:
public: public:
using size_type = std::size_t;
/** /**
* @brief A class to represent an iterator for the Section class * @brief A class to represent an iterator for the Section class
*/ */
@ -391,7 +377,7 @@ namespace docpp {
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Prepend an element to the section * @brief Prepend an element to the section
@ -418,18 +404,18 @@ namespace docpp {
* @param index The index of the element * @param index The index of the element
* @return Element The element at the index * @return Element The element at the index
*/ */
Element at(const int index) const; Element at(const size_type index) const;
/** /**
* @brief Get the section at an index. To get an element, use at() * @brief Get the section at an index. To get an element, use at()
* @param index The index of the section * @param index The index of the section
* @return Section The section at the index * @return Section The section at the index
*/ */
Section at_section(const int index) const; Section at_section(const size_type index) const;
/** /**
* @brief Erase an element from the section. Note that this will NOT change the size/index. * @brief Erase an element from the section. Note that this will NOT change the size/index.
* @param index The index of the element to erase * @param index The index of the element to erase
*/ */
void erase(const int index); void erase(const size_type index);
/** /**
* @brief Erase a section from the section, by reading from a section. The section will be erased if it's identical to section. Note that this will NOT change the size/index. * @brief Erase a section from the section, by reading from a section. The section will be erased if it's identical to section. Note that this will NOT change the size/index.
* @param section The section to erase * @param section The section to erase
@ -443,33 +429,33 @@ namespace docpp {
/** /**
* @brief Find an element in the section * @brief Find an element in the section
* @param element The element to find * @param element The element to find
* @return int The index of the element * @return size_type The index of the element
*/ */
int find(const Element& element); size_type find(const Element& element);
/** /**
* @brief Find a section in the section * @brief Find a section in the section
* @param section The section to find * @param section The section to find
* @return int The index of the section * @return size_type The index of the section
*/ */
int find(const Section& section); size_type find(const Section& section);
/** /**
* @brief Find an element or section in the section * @brief Find an element or section in the section
* @param str The element or section to find * @param str The element or section to find
* @return int The index of the element or section * @return size_type The index of the element or section
*/ */
int find(const std::string& str); size_type find(const std::string& str);
/** /**
* @brief Insert an element into the section * @brief Insert an element into the section
* @param index The index to insert the element * @param index The index to insert the element
* @param element The element to insert * @param element The element to insert
*/ */
void insert(const int index, const Element& element); void insert(const size_type index, const Element& element);
/** /**
* @brief Insert a section into the section * @brief Insert a section into the section
* @param index The index to insert the section * @param index The index to insert the section
* @param section The section to insert * @param section The section to insert
*/ */
void insert(const int index, const Section& section); void insert(const size_type index, const Section& section);
/** /**
* @brief Get the first element of the section * @brief Get the first element of the section
* @return Element The first element of the section * @return Element The first element of the section
@ -492,9 +478,9 @@ namespace docpp {
Section back_section() const; Section back_section() const;
/** /**
* @brief Get the size of the section * @brief Get the size of the section
* @return int The size of the section * @return size_type The size of the section
*/ */
int size() const; size_type size() const;
/** /**
* @brief Construct a new Section object * @brief Construct a new Section object
@ -531,7 +517,7 @@ namespace docpp {
* @param index1 The index of the first element * @param index1 The index of the first element
* @param index2 The index of the second element * @param index2 The index of the second element
*/ */
void swap(const int index1, const int index2); void swap(const size_type index1, const size_type index2);
/** /**
* @brief Swap two elements in the section * @brief Swap two elements in the section
* @param element1 The first element * @param element1 The first element
@ -565,9 +551,14 @@ namespace docpp {
void operator+=(const Element& element); void operator+=(const Element& element);
void operator+=(const Section& section); void operator+=(const Section& section);
Element operator[](const int& index) const; Element operator[](const int& index) const;
}; private:
size_type index{};
std::string tag{};
Properties properties{};
using HTMLSection = Section; std::map<int, Element> elements{};
std::unordered_map<int, Section> sections{};
};
/** /**
* @brief A class to represent an HTML document * @brief A class to represent an HTML document
@ -578,10 +569,12 @@ namespace docpp {
Section document{}; Section document{};
protected: protected:
public: public:
using size_type = std::size_t;
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Get the document * @brief Get the document
@ -625,8 +618,6 @@ namespace docpp {
Document operator=(const Document& document); Document operator=(const Document& document);
Document operator=(const Section& section); Document operator=(const Section& section);
}; };
using HTMLDocument = Document;
} // namespace HTML } // namespace HTML
/** /**
@ -647,10 +638,11 @@ namespace docpp {
std::pair<std::string, std::string> property{}; std::pair<std::string, std::string> property{};
protected: protected:
public: public:
using size_type = std::size_t;
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Construct a new Property object * @brief Construct a new Property object
@ -706,13 +698,12 @@ namespace docpp {
Property operator=(const std::pair<std::string, std::string>& property); Property operator=(const std::pair<std::string, std::string>& property);
}; };
using CSSProperty = Property;
class Element { class Element {
private: private:
std::pair<std::string, std::vector<Property>> element{}; std::pair<std::string, std::vector<Property>> element{};
protected: protected:
public: public:
using size_type = std::size_t;
using iterator = std::vector<Property>::iterator; using iterator = std::vector<Property>::iterator;
using const_iterator = std::vector<Property>::const_iterator; using const_iterator = std::vector<Property>::const_iterator;
using reverse_iterator = std::vector<Property>::reverse_iterator; using reverse_iterator = std::vector<Property>::reverse_iterator;
@ -762,7 +753,7 @@ namespace docpp {
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Construct a new Element object * @brief Construct a new Element object
@ -792,36 +783,36 @@ namespace docpp {
* @param index The index to insert the property * @param index The index to insert the property
* @param property The property to insert * @param property The property to insert
*/ */
void insert(const int index, const Property& property); void insert(const size_type index, const Property& property);
/** /**
* @brief Erase a property from the element * @brief Erase a property from the element
* @param index The index of the property to erase * @param index The index of the property to erase
*/ */
void erase(const int index); void erase(const size_type index);
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param property The property to find * @param property The property to find
* @return int The index of the property * @return size_type The index of the property
*/ */
int find(const Property& property); size_type find(const Property& property);
/** /**
* @brief Get the property at an index * @brief Get the property at an index
* @param index The index of the property * @param index The index of the property
* @return Property The property at the index * @return Property The property at the index
*/ */
Property at(const int index) const; Property at(const size_type index) const;
/** /**
* @brief Find a property in the element * @brief Find a property in the element
* @param str The property to find * @param str The property to find
* @return int The index of the property * @return size_type The index of the property
*/ */
int find(const std::string& str); size_type find(const std::string& str);
/** /**
* @brief Swap two properties in the element * @brief Swap two properties in the element
* @param index1 The index of the first property * @param index1 The index of the first property
* @param index2 The index of the second property * @param index2 The index of the second property
*/ */
void swap(const int index1, const int index2); void swap(const size_type index1, const size_type index2);
/** /**
* @brief Swap two properties in the element * @brief Swap two properties in the element
* @param property1 The first property * @param property1 The first property
@ -840,9 +831,10 @@ namespace docpp {
Property back() const; Property back() const;
/** /**
* @brief Get the size of the element * @brief Get the size of the element
* @return int The size of the element * @return size_type The size of the element
*/ */
int size() const; size_type size() const;
int size();
/** /**
* @brief Set the properties of the element * @brief Set the properties of the element
* @param properties The properties to set * @param properties The properties to set
@ -875,8 +867,6 @@ namespace docpp {
Property operator[](const int& index) const; Property operator[](const int& index) const;
}; };
using CSSElement = Element;
/** /**
* @brief A class to represent a CSS stylesheet * @brief A class to represent a CSS stylesheet
*/ */
@ -885,6 +875,7 @@ namespace docpp {
std::vector<Element> elements{}; std::vector<Element> elements{};
protected: protected:
public: public:
using size_type = std::size_t;
using iterator = std::vector<Element>::iterator; using iterator = std::vector<Element>::iterator;
using const_iterator = std::vector<Element>::const_iterator; using const_iterator = std::vector<Element>::const_iterator;
using reverse_iterator = std::vector<Element>::reverse_iterator; using reverse_iterator = std::vector<Element>::reverse_iterator;
@ -934,7 +925,7 @@ namespace docpp {
/** /**
* @brief The npos value * @brief The npos value
*/ */
static const int npos = -1; static const size_type npos = -1;
/** /**
* @brief Construct a new Stylesheet object * @brief Construct a new Stylesheet object
@ -958,35 +949,35 @@ namespace docpp {
* @param index The index to insert the element * @param index The index to insert the element
* @param element The element to insert * @param element The element to insert
*/ */
void insert(const int index, const Element& element); void insert(const size_type index, const Element& element);
/** /**
* @brief Erase an element from the stylesheet. Note that this will NOT change the size/index. * @brief Erase an element from the stylesheet. Note that this will NOT change the size/index.
* @param index The index of the element to erase * @param index The index of the element to erase
*/ */
void erase(const int index); void erase(const size_type index);
/** /**
* @brief Find an element in the stylesheet * @brief Find an element in the stylesheet
* @param element The element to find * @param element The element to find
* @return int The index of the element * @return size_type The index of the element
*/ */
int find(const Element& element); size_type find(const Element& element);
/** /**
* @brief Find an element in the stylesheet * @brief Find an element in the stylesheet
* @param str The element to find, either the tag or the stylesheet itself * @param str The element to find, either the tag or the stylesheet itself
* @return int The index of the element * @return size_type The index of the element
*/ */
int find(const std::string& str); size_type find(const std::string& str);
/** /**
* @brief Get the element at an index * @brief Get the element at an index
* @param index The index of the element * @param index The index of the element
* @return Element The element at the index * @return Element The element at the index
*/ */
Element at(const int index) const; Element at(const size_type index) const;
/** /**
* @brief Get the size of the stylesheet * @brief Get the size of the stylesheet
* @return int The size of the stylesheet * @return size_type The size of the stylesheet
*/ */
int size() const; size_type size() const;
/** /**
* @brief Get the first element of the stylesheet * @brief Get the first element of the stylesheet
* @return Element The first element of the stylesheet * @return Element The first element of the stylesheet
@ -1002,7 +993,7 @@ namespace docpp {
* @param index1 The index of the first element * @param index1 The index of the first element
* @param index2 The index of the second element * @param index2 The index of the second element
*/ */
void swap(const int index1, const int index2); void swap(const size_type index1, const size_type index2);
/** /**
* @brief Swap two elements in the stylesheet * @brief Swap two elements in the stylesheet
* @param element1 The first element * @param element1 The first element
@ -1029,7 +1020,5 @@ namespace docpp {
void operator+=(const Element& element); void operator+=(const Element& element);
Element operator[](const int& index) const; Element operator[](const int& index) const;
}; };
using CSSStylesheet = Stylesheet;
} }
} }

View file

@ -3,13 +3,6 @@
* Licensed under the LGPL-3.0-or-later license. * Licensed under the LGPL-3.0-or-later license.
* *
* Author: speedie <speedie@speedie.site> * Author: speedie <speedie@speedie.site>
*
* @file docpp.cpp
* @brief Implementation of the docpp library.
* @author speedie
* @date 2024
* @copyright GNU Lesser General Public License 3.0.
* @version 0.0.1
*/ */
#include <include/docpp.hpp> #include <include/docpp.hpp>
@ -80,7 +73,7 @@ std::vector<docpp::HTML::Property> docpp::HTML::Properties::getProperties() cons
return this->properties; return this->properties;
} }
docpp::HTML::Property docpp::HTML::Properties::at(const int index) const { docpp::HTML::Property docpp::HTML::Properties::at(const size_type index) const {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -92,7 +85,7 @@ void docpp::HTML::Properties::set(const std::vector<docpp::HTML::Property>& prop
this->properties = properties; this->properties = properties;
} }
void docpp::HTML::Properties::insert(const int index, const docpp::HTML::Property& property) { void docpp::HTML::Properties::insert(const size_type index, const docpp::HTML::Property& property) {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -100,7 +93,7 @@ void docpp::HTML::Properties::insert(const int index, const docpp::HTML::Propert
this->properties.insert(this->properties.begin() + index, property); this->properties.insert(this->properties.begin() + index, property);
} }
void docpp::HTML::Properties::erase(const int index) { void docpp::HTML::Properties::erase(const size_type index) {
if (index < 0 || index >= this->properties.size()) { if (index < 0 || index >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -116,8 +109,8 @@ void docpp::HTML::Properties::push_back(const docpp::HTML::Property& property) {
this->properties.push_back(property); this->properties.push_back(property);
} }
int docpp::HTML::Properties::find(const docpp::HTML::Property& property) { docpp::HTML::Properties::size_type docpp::HTML::Properties::find(const docpp::HTML::Property& property) {
for (int i{0}; i < this->properties.size(); i++) { for (size_type i{0}; i < this->properties.size(); i++) {
if (!this->properties.at(i).getKey().compare(property.getKey())) { if (!this->properties.at(i).getKey().compare(property.getKey())) {
return i; return i;
} else if (!this->properties.at(i).getValue().compare(property.getValue())) { } else if (!this->properties.at(i).getValue().compare(property.getValue())) {
@ -134,8 +127,8 @@ int docpp::HTML::Properties::find(const docpp::HTML::Property& property) {
return docpp::HTML::Properties::npos; return docpp::HTML::Properties::npos;
} }
int docpp::HTML::Properties::find(const std::string& str) { docpp::HTML::Properties::size_type docpp::HTML::Properties::find(const std::string& str) {
for (int i{0}; i < this->properties.size(); i++) { for (size_type i{0}; i < this->properties.size(); i++) {
if (!this->properties.at(i).getKey().compare(str) || !this->properties.at(i).getValue().compare(str)) { if (!this->properties.at(i).getKey().compare(str) || !this->properties.at(i).getValue().compare(str)) {
return i; return i;
} else if (this->properties.at(i).getKey().find(str) != std::string::npos || this->properties.at(i).getValue().find(str) != std::string::npos) { } else if (this->properties.at(i).getKey().find(str) != std::string::npos || this->properties.at(i).getValue().find(str) != std::string::npos) {
@ -154,11 +147,11 @@ docpp::HTML::Property docpp::HTML::Properties::back() const {
return this->properties.back(); return this->properties.back();
} }
int docpp::HTML::Properties::size() const { docpp::HTML::Properties::size_type docpp::HTML::Properties::size() const {
return this->properties.size(); return this->properties.size();
} }
void docpp::HTML::Properties::swap(const int index1, const int index2) { void docpp::HTML::Properties::swap(const size_type index1, const size_type index2) {
if (index1 < 0 || index1 >= this->properties.size() || index2 < 0 || index2 >= this->properties.size()) { if (index1 < 0 || index1 >= this->properties.size() || index2 < 0 || index2 >= this->properties.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -196,7 +189,7 @@ std::string docpp::HTML::Element::get(const int formatting, const int tabc) cons
if (this->type == docpp::HTML::TYPE_TEXT) { if (this->type == docpp::HTML::TYPE_TEXT) {
return this->data; return this->data;
} else if (this->type == docpp::HTML::TYPE_TEXT_TAB) { } else if (this->type == docpp::HTML::TYPE_TEXT_TAB) {
for (int i{0}; i < tabc; i++) { for (size_type i{0}; i < tabc; i++) {
ret += "\t"; ret += "\t";
} }
@ -204,7 +197,7 @@ std::string docpp::HTML::Element::get(const int formatting, const int tabc) cons
} }
if (formatting == docpp::HTML::FORMATTING_PRETTY) { if (formatting == docpp::HTML::FORMATTING_PRETTY) {
for (int i{0}; i < tabc; i++) { for (size_type i{0}; i < tabc; i++) {
ret += "\t"; ret += "\t";
} }
} }
@ -296,7 +289,7 @@ void docpp::HTML::Section::set(const int tag, const Properties& properties) {
} }
void docpp::HTML::Section::push_front(const Element& element) { void docpp::HTML::Section::push_front(const Element& element) {
for (int i{this->index}; i > 0; i--) { for (size_type i{this->index}; i > 0; i--) {
this->elements[i] = this->elements.at(i - 1); this->elements[i] = this->elements.at(i - 1);
} }
@ -305,7 +298,7 @@ void docpp::HTML::Section::push_front(const Element& element) {
} }
void docpp::HTML::Section::push_front(const Section& section) { void docpp::HTML::Section::push_front(const Section& section) {
for (int i{this->index}; i > 0; i--) { for (size_type i{this->index}; i > 0; i--) {
this->sections.at(i) = this->sections.at(i - 1); this->sections.at(i) = this->sections.at(i - 1);
} }
@ -321,7 +314,7 @@ void docpp::HTML::Section::push_back(const Section& section) {
this->sections[this->index++] = section; this->sections[this->index++] = section;
} }
void docpp::HTML::Section::erase(const int index) { void docpp::HTML::Section::erase(const size_type index) {
bool erased{false}; bool erased{false};
if (this->elements.find(index) != this->elements.end()) { if (this->elements.find(index) != this->elements.end()) {
@ -338,7 +331,7 @@ void docpp::HTML::Section::erase(const int index) {
} }
void docpp::HTML::Section::erase(const Section& section) { void docpp::HTML::Section::erase(const Section& section) {
for (int i{0}; i < this->size(); i++) { for (size_type i{0}; i < this->size(); i++) {
const auto it = this->getSections().at(i); const auto it = this->getSections().at(i);
if (it.get() == section.get()) { if (it.get() == section.get()) {
@ -351,7 +344,7 @@ void docpp::HTML::Section::erase(const Section& section) {
} }
void docpp::HTML::Section::erase(const Element& element) { void docpp::HTML::Section::erase(const Element& element) {
for (int i{0}; i < this->size(); i++) { for (size_type i{0}; i < this->size(); i++) {
const auto it = this->getElements().at(i); const auto it = this->getElements().at(i);
if (it.get() == element.get()) { if (it.get() == element.get()) {
@ -363,7 +356,7 @@ void docpp::HTML::Section::erase(const Element& element) {
throw docpp::out_of_range("Element not found"); throw docpp::out_of_range("Element not found");
} }
void docpp::HTML::Section::insert(const int index, const Element& element) { void docpp::HTML::Section::insert(const size_type index, const Element& element) {
if (this->sections.find(index) != this->sections.end()) { if (this->sections.find(index) != this->sections.end()) {
throw docpp::invalid_argument("Index already occupied by a section"); throw docpp::invalid_argument("Index already occupied by a section");
} else { } else {
@ -373,12 +366,12 @@ void docpp::HTML::Section::insert(const int index, const Element& element) {
this->index = std::max(this->index, index) + 1; this->index = std::max(this->index, index) + 1;
} }
void docpp::HTML::Section::insert(const int index, const Section& section) { void docpp::HTML::Section::insert(const size_type index, const Section& section) {
this->sections[index] = section; this->sections[index] = section;
this->index = std::max(this->index, index) + 1; this->index = std::max(this->index, index) + 1;
} }
docpp::HTML::Element docpp::HTML::Section::at(const int index) const { docpp::HTML::Element docpp::HTML::Section::at(const size_type index) const {
if (this->elements.find(index) != this->elements.end()) { if (this->elements.find(index) != this->elements.end()) {
return this->elements.at(index); return this->elements.at(index);
} }
@ -386,7 +379,7 @@ docpp::HTML::Element docpp::HTML::Section::at(const int index) const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
docpp::HTML::Section docpp::HTML::Section::at_section(const int index) const { docpp::HTML::Section docpp::HTML::Section::at_section(const size_type index) const {
if (this->sections.find(index) != this->sections.end()) { if (this->sections.find(index) != this->sections.end()) {
return this->sections.at(index); return this->sections.at(index);
} }
@ -394,8 +387,8 @@ docpp::HTML::Section docpp::HTML::Section::at_section(const int index) const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
int docpp::HTML::Section::find(const Element& element) { docpp::HTML::Section::size_type docpp::HTML::Section::find(const Element& element) {
for (int i{0}; i < this->size(); i++) { for (size_type i{0}; i < this->size(); i++) {
const auto it = this->getElements().at(i); const auto it = this->getElements().at(i);
if (it.get() == element.get()) { if (it.get() == element.get()) {
@ -406,8 +399,8 @@ int docpp::HTML::Section::find(const Element& element) {
return docpp::HTML::Section::npos; return docpp::HTML::Section::npos;
} }
int docpp::HTML::Section::find(const Section& section) { docpp::HTML::Section::size_type docpp::HTML::Section::find(const Section& section) {
for (int i{0}; i < this->size(); i++) { for (size_type i{0}; i < this->size(); i++) {
const auto it = this->getSections().at(i); const auto it = this->getSections().at(i);
if (it.get() == section.get()) { if (it.get() == section.get()) {
@ -418,10 +411,10 @@ int docpp::HTML::Section::find(const Section& section) {
return docpp::HTML::Section::npos; return docpp::HTML::Section::npos;
} }
int docpp::HTML::Section::find(const std::string& str) { docpp::HTML::Section::size_type docpp::HTML::Section::find(const std::string& str) {
const auto elements = this->getElements(); const auto elements = this->getElements();
for (int i{0}; i < elements.size(); i++) { for (size_type i{0}; i < elements.size(); i++) {
if (!elements.at(i).get().compare(str)) { if (!elements.at(i).get().compare(str)) {
return i; return i;
} }
@ -429,7 +422,7 @@ int docpp::HTML::Section::find(const std::string& str) {
const auto sections = this->getSections(); const auto sections = this->getSections();
for (int i{0}; i < sections.size(); i++) { for (size_type i{0}; i < sections.size(); i++) {
if (!sections.at(i).get().compare(str)) { if (!sections.at(i).get().compare(str)) {
return i; return i;
} }
@ -470,14 +463,14 @@ docpp::HTML::Section docpp::HTML::Section::back_section() const {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
int docpp::HTML::Section::size() const { docpp::HTML::Section::size_type docpp::HTML::Section::size() const {
return this->index; return this->index;
} }
std::vector<docpp::HTML::Element> docpp::HTML::Section::getElements() const { std::vector<docpp::HTML::Element> docpp::HTML::Section::getElements() const {
std::vector<docpp::HTML::Element> ret{}; std::vector<docpp::HTML::Element> ret{};
ret.reserve(this->index); ret.reserve(this->index);
for (int i{0}; i < this->index; i++) { for (size_type i{0}; i < this->index; i++) {
if (this->elements.find(i) != this->elements.end()) { if (this->elements.find(i) != this->elements.end()) {
ret.push_back(this->elements.at(i)); ret.push_back(this->elements.at(i));
} }
@ -489,7 +482,7 @@ std::vector<docpp::HTML::Section> docpp::HTML::Section::getSections() const {
std::vector<docpp::HTML::Section> ret{}; std::vector<docpp::HTML::Section> ret{};
ret.reserve(this->index); ret.reserve(this->index);
for (int i{0}; i < this->index; i++) { for (size_type i{0}; i < this->index; i++) {
if (this->sections.find(i) != this->sections.end()) { if (this->sections.find(i) != this->sections.end()) {
ret.push_back(this->sections.at(i)); ret.push_back(this->sections.at(i));
} }
@ -511,7 +504,7 @@ std::string docpp::HTML::Section::get(const int formatting, const int tabc) cons
} }
if (formatting == docpp::HTML::FORMATTING_PRETTY) { if (formatting == docpp::HTML::FORMATTING_PRETTY) {
for (int i{0}; i < tabcount; i++) { for (size_type i{0}; i < tabcount; i++) {
ret += "\t"; ret += "\t";
} }
} }
@ -533,7 +526,7 @@ std::string docpp::HTML::Section::get(const int formatting, const int tabc) cons
} }
} }
for (int i{0}; i < this->index; i++) { for (size_type i{0}; i < this->index; i++) {
if (this->elements.find(i) != this->elements.end()) { if (this->elements.find(i) != this->elements.end()) {
ret += this->elements.at(i).get(formatting, tabcount + 1); ret += this->elements.at(i).get(formatting, tabcount + 1);
} else if (this->sections.find(i) != this->sections.end()) { } else if (this->sections.find(i) != this->sections.end()) {
@ -546,7 +539,7 @@ std::string docpp::HTML::Section::get(const int formatting, const int tabc) cons
} }
if (formatting == docpp::HTML::FORMATTING_PRETTY) { if (formatting == docpp::HTML::FORMATTING_PRETTY) {
for (int i{0}; i < tabcount; i++) { for (size_type i{0}; i < tabcount; i++) {
ret += "\t"; ret += "\t";
} }
} }
@ -556,7 +549,7 @@ std::string docpp::HTML::Section::get(const int formatting, const int tabc) cons
return std::move(ret); return std::move(ret);
} }
void docpp::HTML::Section::swap(const int index1, const int index2) { void docpp::HTML::Section::swap(const size_type index1, const size_type index2) {
if (this->elements.find(index1) != this->elements.end() && this->elements.find(index2) != this->elements.end()) { if (this->elements.find(index1) != this->elements.end() && this->elements.find(index2) != this->elements.end()) {
std::swap(this->elements[index1], this->elements[index2]); std::swap(this->elements[index1], this->elements[index2]);
} else if (this->sections.find(index1) != this->sections.end() && this->sections.find(index2) != this->sections.end()) { } else if (this->sections.find(index1) != this->sections.end() && this->sections.find(index2) != this->sections.end()) {
@ -694,7 +687,7 @@ void docpp::CSS::Element::push_back(const Property& property) {
this->element.second.push_back(property); this->element.second.push_back(property);
} }
void docpp::CSS::Element::insert(const int index, const Property& property) { void docpp::CSS::Element::insert(const size_type index, const Property& property) {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -702,7 +695,7 @@ void docpp::CSS::Element::insert(const int index, const Property& property) {
this->element.second.insert(this->element.second.begin() + index, property); this->element.second.insert(this->element.second.begin() + index, property);
} }
void docpp::CSS::Element::erase(const int index) { void docpp::CSS::Element::erase(const size_type index) {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -710,7 +703,7 @@ void docpp::CSS::Element::erase(const int index) {
this->element.second.erase(this->element.second.begin() + index); this->element.second.erase(this->element.second.begin() + index);
} }
docpp::CSS::Property docpp::CSS::Element::at(const int index) const { docpp::CSS::Property docpp::CSS::Element::at(const size_type index) const {
if (index < 0 || index >= this->element.second.size()) { if (index < 0 || index >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -718,8 +711,8 @@ docpp::CSS::Property docpp::CSS::Element::at(const int index) const {
return this->element.second.at(index); return this->element.second.at(index);
} }
int docpp::CSS::Element::find(const Property& property) { docpp::CSS::Element::size_type docpp::CSS::Element::find(const Property& property) {
for (int i{0}; i < this->element.second.size(); i++) { for (size_type i{0}; i < this->element.second.size(); i++) {
if (this->element.second.at(i).get() == property.get()) { if (this->element.second.at(i).get() == property.get()) {
return i; return i;
} }
@ -728,8 +721,8 @@ int docpp::CSS::Element::find(const Property& property) {
return docpp::CSS::Element::npos; return docpp::CSS::Element::npos;
} }
int docpp::CSS::Element::find(const std::string& str) { docpp::CSS::Element::size_type docpp::CSS::Element::find(const std::string& str) {
for (int i{0}; i < this->element.second.size(); i++) { for (size_type i{0}; i < this->element.second.size(); i++) {
if (!this->element.second.at(i).getKey().compare(str) || !this->element.second.at(i).getValue().compare(str)) { if (!this->element.second.at(i).getKey().compare(str) || !this->element.second.at(i).getValue().compare(str)) {
return i; return i;
} }
@ -746,11 +739,11 @@ docpp::CSS::Property docpp::CSS::Element::back() const {
return this->element.second.back(); return this->element.second.back();
} }
int docpp::CSS::Element::size() const { docpp::CSS::Element::size_type docpp::CSS::Element::size() const {
return this->element.second.size(); return this->element.second.size();
} }
void docpp::CSS::Element::swap(const int index1, const int index2) { void docpp::CSS::Element::swap(const size_type index1, const size_type index2) {
if (index1 < 0 || index1 >= this->element.second.size() || index2 < 0 || index2 >= this->element.second.size()) { if (index1 < 0 || index1 >= this->element.second.size() || index2 < 0 || index2 >= this->element.second.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -777,7 +770,7 @@ std::string docpp::CSS::Element::get(const int formatting, const int tabc) const
if (!it.getValue().compare("")) continue; if (!it.getValue().compare("")) continue;
if (formatting == docpp::CSS::FORMATTING_PRETTY) { if (formatting == docpp::CSS::FORMATTING_PRETTY) {
for (int i{0}; i < tabc + 1; i++) { for (size_type i{0}; i < tabc + 1; i++) {
ret += "\t"; ret += "\t";
} }
} }
@ -823,7 +816,7 @@ void docpp::CSS::Stylesheet::push_back(const Element& element) {
this->elements.push_back(element); this->elements.push_back(element);
} }
void docpp::CSS::Stylesheet::insert(const int index, const Element& element) { void docpp::CSS::Stylesheet::insert(const size_type index, const Element& element) {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -831,7 +824,7 @@ void docpp::CSS::Stylesheet::insert(const int index, const Element& element) {
this->elements.insert(this->elements.begin() + index, element); this->elements.insert(this->elements.begin() + index, element);
} }
void docpp::CSS::Stylesheet::erase(const int index) { void docpp::CSS::Stylesheet::erase(const size_type index) {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -852,7 +845,7 @@ docpp::CSS::Element docpp::CSS::Stylesheet::operator[](const int& index) const {
return this->at(index); return this->at(index);
} }
docpp::CSS::Element docpp::CSS::Stylesheet::at(const int index) const { docpp::CSS::Element docpp::CSS::Stylesheet::at(const size_type index) const {
if (index < 0 || index >= this->elements.size()) { if (index < 0 || index >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }
@ -860,8 +853,8 @@ docpp::CSS::Element docpp::CSS::Stylesheet::at(const int index) const {
return this->elements.at(index); return this->elements.at(index);
} }
int docpp::CSS::Stylesheet::find(const Element& element) { docpp::CSS::Stylesheet::size_type docpp::CSS::Stylesheet::find(const Element& element) {
for (int i{0}; i < this->elements.size(); i++) { for (size_type i{0}; i < this->elements.size(); i++) {
if (this->elements.at(i).get() == element.get()) { if (this->elements.at(i).get() == element.get()) {
return i; return i;
} }
@ -870,8 +863,8 @@ int docpp::CSS::Stylesheet::find(const Element& element) {
return docpp::CSS::Stylesheet::npos; return docpp::CSS::Stylesheet::npos;
} }
int docpp::CSS::Stylesheet::find(const std::string& str) { docpp::CSS::Stylesheet::size_type docpp::CSS::Stylesheet::find(const std::string& str) {
for (int i{0}; i < this->elements.size(); i++) { for (size_type i{0}; i < this->elements.size(); i++) {
if (!this->elements.at(i).get().compare(str) || !this->elements.at(i).getTag().compare(str)) { if (!this->elements.at(i).get().compare(str) || !this->elements.at(i).getTag().compare(str)) {
return i; return i;
} }
@ -880,7 +873,7 @@ int docpp::CSS::Stylesheet::find(const std::string& str) {
return docpp::CSS::Stylesheet::npos; return docpp::CSS::Stylesheet::npos;
} }
int docpp::CSS::Stylesheet::size() const { docpp::CSS::Stylesheet::size_type docpp::CSS::Stylesheet::size() const {
return this->elements.size(); return this->elements.size();
} }
@ -892,7 +885,7 @@ docpp::CSS::Element docpp::CSS::Stylesheet::back() const {
return this->elements.back(); return this->elements.back();
} }
void docpp::CSS::Stylesheet::swap(const int index1, const int index2) { void docpp::CSS::Stylesheet::swap(const size_type index1, const size_type index2) {
if (index1 < 0 || index1 >= this->elements.size() || index2 < 0 || index2 >= this->elements.size()) { if (index1 < 0 || index1 >= this->elements.size() || index2 < 0 || index2 >= this->elements.size()) {
throw docpp::out_of_range("Index out of range"); throw docpp::out_of_range("Index out of range");
} }

View file

@ -64,7 +64,7 @@ SCENARIO("Test HTML", "[HTML]") {
section.push_back(docpp::HTML::Element("p", {}, "Test 2")); 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 3"));
int pos = section.find(docpp::HTML::Element("p", {}, "Test 2")); std::size_t pos = section.find(docpp::HTML::Element("p", {}, "Test 2"));
section.insert(pos, docpp::HTML::Element("p", {}, "Test 2.5")); section.insert(pos, docpp::HTML::Element("p", {}, "Test 2.5"));
REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 2.5</p><p>Test 3</p></html>"); REQUIRE(section.get() == "<html><p>Test 1</p><p>Test 2.5</p><p>Test 3</p></html>");
@ -78,7 +78,7 @@ SCENARIO("Test HTML", "[HTML]") {
section.push_back(docpp::HTML::Element("p", {}, "Test 2")); 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 3"));
int pos = section.find(docpp::HTML::Element("p", {}, "Test 2")); std::size_t pos = section.find(docpp::HTML::Element("p", {}, "Test 2"));
section.erase(pos); section.erase(pos);
@ -206,11 +206,11 @@ SCENARIO("Test HTML", "[HTML]") {
section.push_back(docpp::HTML::Element("p", {}, "Test 5")); section.push_back(docpp::HTML::Element("p", {}, "Test 5"));
section.push_back(docpp::HTML::Element("p", {}, "Test 6")); section.push_back(docpp::HTML::Element("p", {}, "Test 6"));
const int pos{section.find("<p>Test 2</p>")}; const std::size_t pos{section.find("<p>Test 2</p>")};
REQUIRE(pos != docpp::HTML::Section::npos); REQUIRE(pos != docpp::HTML::Section::npos);
const int pos2{section.find("<p>Test 6</p>")}; const std::size_t pos2{section.find("<p>Test 6</p>")};
section.erase(pos); section.erase(pos);
section.erase(pos2); section.erase(pos2);