Implement at() methods for several classes.
This commit is contained in:
parent
cddf11235f
commit
aca33e80d5
|
@ -116,6 +116,18 @@ namespace docpp {
|
||||||
* @param properties The properties to set
|
* @param properties The properties to set
|
||||||
*/
|
*/
|
||||||
void set(const std::vector<HTMLProperty>& properties);
|
void set(const std::vector<HTMLProperty>& properties);
|
||||||
|
/**
|
||||||
|
* @brief Get the property at an index
|
||||||
|
* @param index The index of the property
|
||||||
|
* @return HTMLProperty The property at the index
|
||||||
|
*/
|
||||||
|
HTMLProperty 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);
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
|
@ -268,6 +280,18 @@ namespace docpp {
|
||||||
* @param section The section to add
|
* @param section The section to add
|
||||||
*/
|
*/
|
||||||
void push_back(const HTMLSection& section);
|
void push_back(const HTMLSection& 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
|
||||||
|
*/
|
||||||
|
HTMLElement 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
|
||||||
|
*/
|
||||||
|
HTMLSection at_section(const int index) const;
|
||||||
/**
|
/**
|
||||||
* @brief Erase an element from the section. Note that this will NOT change the size/index.
|
* @brief Erase an element from the section. Note that this will NOT change the size/index.
|
||||||
* @param index The index of the element to erase
|
* @param index The index of the element to erase
|
||||||
|
@ -552,6 +576,12 @@ namespace docpp {
|
||||||
* @return int The index of the property
|
* @return int The index of the property
|
||||||
*/
|
*/
|
||||||
int find(const CSSProperty& property);
|
int find(const CSSProperty& property);
|
||||||
|
/**
|
||||||
|
* @brief Get the property at an index
|
||||||
|
* @param index The index of the property
|
||||||
|
* @return CSSProperty The property at the index
|
||||||
|
*/
|
||||||
|
CSSProperty at(const int index) const;
|
||||||
/**
|
/**
|
||||||
* @brief Find a property in the element
|
* @brief Find a property in the element
|
||||||
* @param str The property to find
|
* @param str The property to find
|
||||||
|
@ -655,6 +685,12 @@ namespace docpp {
|
||||||
* @return int The index of the element
|
* @return int The index of the element
|
||||||
*/
|
*/
|
||||||
int find(const std::string& str);
|
int find(const std::string& str);
|
||||||
|
/**
|
||||||
|
* @brief Get the element at an index
|
||||||
|
* @param index The index of the element
|
||||||
|
* @return CSSElement The element at the index
|
||||||
|
*/
|
||||||
|
CSSElement at(const int index) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the size of the stylesheet
|
* @brief Get the size of the stylesheet
|
||||||
* @return int The size of the stylesheet
|
* @return int The size of the stylesheet
|
||||||
|
|
|
@ -63,10 +63,26 @@ std::vector<docpp::HTML::HTMLProperty> docpp::HTML::HTMLElementProperties::getPr
|
||||||
return this->properties;
|
return this->properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docpp::HTML::HTMLProperty docpp::HTML::HTMLElementProperties::at(const int index) const {
|
||||||
|
if (index < 0 || index >= this->properties.size()) {
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->properties.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
void docpp::HTML::HTMLElementProperties::set(const std::vector<docpp::HTML::HTMLProperty>& properties) {
|
void docpp::HTML::HTMLElementProperties::set(const std::vector<docpp::HTML::HTMLProperty>& properties) {
|
||||||
this->properties = properties;
|
this->properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void docpp::HTML::HTMLElementProperties::insert(const int index, const docpp::HTML::HTMLProperty& property) {
|
||||||
|
if (index < 0 || index >= this->properties.size()) {
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->properties.insert(this->properties.begin() + index, property);
|
||||||
|
}
|
||||||
|
|
||||||
void docpp::HTML::HTMLElementProperties::erase(const int index) {
|
void docpp::HTML::HTMLElementProperties::erase(const int index) {
|
||||||
if (index < 0 || index >= this->properties.size()) {
|
if (index < 0 || index >= this->properties.size()) {
|
||||||
throw std::out_of_range("Index out of range");
|
throw std::out_of_range("Index out of range");
|
||||||
|
@ -302,6 +318,22 @@ void docpp::HTML::HTMLSection::insert(const int index, const HTMLSection& sectio
|
||||||
this->index = std::max(this->index, index) + 1;
|
this->index = std::max(this->index, index) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docpp::HTML::HTMLElement docpp::HTML::HTMLSection::at(const int index) const {
|
||||||
|
if (this->elements.find(index) != this->elements.end()) {
|
||||||
|
return this->elements.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
docpp::HTML::HTMLSection docpp::HTML::HTMLSection::at_section(const int index) const {
|
||||||
|
if (this->sections.find(index) != this->sections.end()) {
|
||||||
|
return this->sections.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
int docpp::HTML::HTMLSection::find(const HTMLElement& element) {
|
int docpp::HTML::HTMLSection::find(const HTMLElement& element) {
|
||||||
for (int i{0}; i < this->size(); i++) {
|
for (int i{0}; i < this->size(); i++) {
|
||||||
const auto it = this->getHTMLElements().at(i);
|
const auto it = this->getHTMLElements().at(i);
|
||||||
|
@ -525,6 +557,14 @@ void docpp::CSS::CSSElement::erase(const int index) {
|
||||||
this->element.second.erase(this->element.second.begin() + index);
|
this->element.second.erase(this->element.second.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docpp::CSS::CSSProperty docpp::CSS::CSSElement::at(const int index) const {
|
||||||
|
if (index < 0 || index >= this->element.second.size()) {
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->element.second.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
int docpp::CSS::CSSElement::find(const CSSProperty& property) {
|
int docpp::CSS::CSSElement::find(const CSSProperty& property) {
|
||||||
for (int i{0}; i < this->element.second.size(); i++) {
|
for (int i{0}; i < this->element.second.size(); i++) {
|
||||||
if (this->element.second.at(i).get() == property.get()) {
|
if (this->element.second.at(i).get() == property.get()) {
|
||||||
|
@ -632,6 +672,14 @@ void docpp::CSS::CSSStylesheet::erase(const int index) {
|
||||||
this->elements.erase(this->elements.begin() + index);
|
this->elements.erase(this->elements.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docpp::CSS::CSSElement docpp::CSS::CSSStylesheet::at(const int index) const {
|
||||||
|
if (index < 0 || index >= this->elements.size()) {
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->elements.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
int docpp::CSS::CSSStylesheet::find(const CSSElement& element) {
|
int docpp::CSS::CSSStylesheet::find(const CSSElement& element) {
|
||||||
for (int i{0}; i < this->elements.size(); i++) {
|
for (int i{0}; i < this->elements.size(); i++) {
|
||||||
if (this->elements.at(i).get() == element.get()) {
|
if (this->elements.at(i).get() == element.get()) {
|
||||||
|
|
|
@ -252,6 +252,9 @@ SCENARIO("Test HTML", "[HTML]") {
|
||||||
|
|
||||||
const int pos2 = prop.find("class2");
|
const int pos2 = prop.find("class2");
|
||||||
|
|
||||||
|
REQUIRE(prop.at(pos2).getKey() == "class");
|
||||||
|
REQUIRE(prop.at(pos2).getValue() == "class1 class2 class3");
|
||||||
|
|
||||||
REQUIRE(pos2 != docpp::HTML::HTMLElementProperties::npos);
|
REQUIRE(pos2 != docpp::HTML::HTMLElementProperties::npos);
|
||||||
|
|
||||||
const int pos3 = prop.find("class4");
|
const int pos3 = prop.find("class4");
|
||||||
|
|
Loading…
Reference in a new issue