From ee0720cd679abae670a3c5695647d931cdd50150 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 13 May 2024 12:00:47 +0200 Subject: [PATCH] Change case for many methods to closer align with the standard library. --- examples/hello-world.cpp | 2 +- include/docpp.hpp | 54 +++++++++--------- src/docpp.cpp | 120 +++++++++++++++++++-------------------- tests/test.cpp | 28 ++++----- 4 files changed, 102 insertions(+), 102 deletions(-) diff --git a/examples/hello-world.cpp b/examples/hello-world.cpp index e40c1d6..7cdff9a 100644 --- a/examples/hello-world.cpp +++ b/examples/hello-world.cpp @@ -12,7 +12,7 @@ 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::Document::setDocType() to set the doctype to your preferred value. + * use docpp::HTML::Document::set_doctype() to set the doctype to your preferred value. * * To get the document as an std::string object, call doc.get(). */ diff --git a/include/docpp.hpp b/include/docpp.hpp index 1828ef9..b98c812 100644 --- a/include/docpp.hpp +++ b/include/docpp.hpp @@ -96,22 +96,22 @@ namespace docpp { * @brief Get the key of the property * @return std::string The key of the property */ - std::string getKey() const; + std::string get_key() const; /** * @brief Get the key of the property in a specific type * @return T The key of the property */ - template T getKey() const; + template T get_key() const; /** * @brief Get the value of the property * @return std::string The value of the property */ - std::string getValue() const; + std::string get_value() const; /** * @brief Get the value of the property in a specific type * @return T The value of the property */ - template T getValue() const; + template T get_value() const; /** * @brief Get the property. * @return std::pair The value of the property @@ -126,12 +126,12 @@ namespace docpp { * @brief Set the key of the property. * @param key The key. */ - void setKey(const std::string& key); + void set_key(const std::string& key); /** * @brief Set the value of the property. * @param value The value. */ - void setValue(const std::string& value); + void set_value(const std::string& value); /** * @brief Set the property * @param property The property. @@ -203,7 +203,7 @@ namespace docpp { * @brief Get the properties of the element * @return std::vector The properties of the element */ - std::vector getProperties() const; + std::vector get_properties() const; /** * @brief Set the properties of the element * @param properties The properties to set @@ -346,23 +346,23 @@ namespace docpp { * @brief Get the tag of the element * @return std::string The data of the element */ - std::string getTag() const; + std::string get_tag() const; /** * @brief Get the tag of the element in a specific type * @return T The tag of the element */ - template T getTag() const; + template T get_tag() const; /** * @brief Get the data of the element * @return std::string The data of the element */ - std::string getData() const; + std::string get_data() const; /** * @brief Get the data of the element in a specific type * @return T The data of the element */ - template T getData() const; + template T get_data() const; Element operator=(const Element& element); void operator+=(const std::string& data); @@ -565,12 +565,12 @@ namespace docpp { * @brief Get the elements of the section * @return std::vector The elements of the section */ - std::vector getElements() const; + std::vector get_elements() const; /** * @brief Get the sections of the section * @return std::vector
The sections of the section */ - std::vector
getSections() const; + std::vector
get_sections() const; /** * @brief Dump the entire section. @@ -628,18 +628,18 @@ namespace docpp { * @brief Get the section * @return Section The section */ - Section& getSection(); + Section& get_section(); /** * @brief Get the doctype of the document * @return std::string The doctype of the document */ - std::string getDoctype() const; + std::string get_doctype() const; /** * @brief Get the doctype of the document in a specific type * @return T The doctype of the document */ - template T getDoctype() const; + template T get_doctype() const; /** * @brief Set the document @@ -650,7 +650,7 @@ namespace docpp { * @brief Set the doctype of the document * @param doctype The doctype to set */ - void setDoctype(const std::string& doctype); + void set_doctype(const std::string& doctype); /** * @brief Construct a new Document object */ @@ -707,22 +707,22 @@ namespace docpp { * @brief Get the key of the property * @return std::string The key of the property */ - std::string getKey() const; + std::string get_key() const; /** * @brief Get the key of the property in a specific type * @return T The key of the property */ - template T getKey() const; + template T get_key() const; /** * @brief Get the value of the property * @return std::string The value of the property */ - std::string getValue() const; + std::string get_value() const; /** * @brief Get the value of the property in a specific type * @return T The value of the property */ - template T getValue() const; + template T get_value() const; /** * @brief Get the property. * @return std::pair The value of the property @@ -737,12 +737,12 @@ namespace docpp { * @brief Set the key of the property. * @param key The key. */ - void setKey(const std::string& key); + void set_key(const std::string& key); /** * @brief Set the value of the property. * @param value The value. */ - void setValue(const std::string& value); + void set_value(const std::string& value); /** * @brief Set the property * @param property The property. @@ -922,17 +922,17 @@ namespace docpp { * @brief Get the tag of the element * @return std::string The tag of the element */ - std::string getTag() const; + std::string get_tag() const; /** * @brief Get the tag of the element in a specific type * @return T The tag of the element */ - template T getTag() const; + template T get_tag() const; /** * @brief Get the properties of the element * @return std::vector The properties of the element */ - std::vector getProperties() const; + std::vector get_properties() const; Element operator=(const Element& element); Element operator=(const std::pair>& element); @@ -1082,7 +1082,7 @@ namespace docpp { * @brief Get the elements of the stylesheet * @return std::vector The elements of the stylesheet */ - std::vector getElements() const; + std::vector get_elements() const; /** * @brief Get the stylesheet * @return std::string The stylesheet diff --git a/src/docpp.cpp b/src/docpp.cpp index a7390ca..0b351e5 100644 --- a/src/docpp.cpp +++ b/src/docpp.cpp @@ -10,27 +10,27 @@ #include docpp::HTML::Property::Property(const std::string& key, const std::string& value) { - this->setKey(key); - this->setValue(value); + this->set_key(key); + this->set_value(value); } docpp::HTML::Property::Property(const std::pair& property) { this->set(property); } -std::string docpp::HTML::Property::getKey() const { +std::string docpp::HTML::Property::get_key() const { return this->property.first; } -template T docpp::HTML::Property::getKey() const { +template T docpp::HTML::Property::get_key() const { return T(this->property.first); } -std::string docpp::HTML::Property::getValue() const { +std::string docpp::HTML::Property::get_value() const { return this->property.second; } -template T docpp::HTML::Property::getValue() const { +template T docpp::HTML::Property::get_value() const { return T(this->property.second); } @@ -42,11 +42,11 @@ template std::pair docpp::HTML::Property::get() const { return T(this->property); } -void docpp::HTML::Property::setKey(const std::string& key) { +void docpp::HTML::Property::set_key(const std::string& key) { this->property.first = key; } -void docpp::HTML::Property::setValue(const std::string& value) { +void docpp::HTML::Property::set_value(const std::string& value) { this->property.second = value; } @@ -68,7 +68,7 @@ docpp::HTML::Properties docpp::HTML::Properties::operator=(const docpp::HTML::Pr } docpp::HTML::Properties docpp::HTML::Properties::operator=(const docpp::HTML::Properties& properties) { - this->set(properties.getProperties()); + this->set(properties.get_properties()); return *this; } @@ -81,7 +81,7 @@ void docpp::HTML::Properties::operator+=(const docpp::HTML::Property& property) this->push_back(property); } -std::vector docpp::HTML::Properties::getProperties() const { +std::vector docpp::HTML::Properties::get_properties() const { return this->properties; } @@ -123,13 +123,13 @@ void docpp::HTML::Properties::push_back(const docpp::HTML::Property& property) { docpp::HTML::Properties::size_type docpp::HTML::Properties::find(const docpp::HTML::Property& property) { for (size_type i{0}; i < this->properties.size(); i++) { - if (!this->properties.at(i).getKey().compare(property.getKey())) { + if (!this->properties.at(i).get_key().compare(property.get_key())) { return i; - } else if (!this->properties.at(i).getValue().compare(property.getValue())) { + } else if (!this->properties.at(i).get_value().compare(property.get_value())) { return i; - } else if (this->properties.at(i).getValue().find(property.getValue()) != std::string::npos) { + } else if (this->properties.at(i).get_value().find(property.get_value()) != std::string::npos) { return i; - } else if (this->properties.at(i).getKey().find(property.getKey()) != std::string::npos) { + } else if (this->properties.at(i).get_key().find(property.get_key()) != std::string::npos) { return i; } else if (this->properties.at(i).get() == property.get()) { return i; @@ -141,9 +141,9 @@ docpp::HTML::Properties::size_type docpp::HTML::Properties::find(const docpp::HT docpp::HTML::Properties::size_type docpp::HTML::Properties::find(const std::string& str) { 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).get_key().compare(str) || !this->properties.at(i).get_value().compare(str)) { 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).get_key().find(str) != std::string::npos || this->properties.at(i).get_value().find(str) != std::string::npos) { return i; } } @@ -180,7 +180,7 @@ docpp::HTML::Element::Element(const std::string& tag, const Properties& properti } docpp::HTML::Element docpp::HTML::Element::operator=(const docpp::HTML::Element& element) { - this->set(element.getTag(), element.properties, element.getData(), element.type); + this->set(element.get_tag(), element.properties, element.get_data(), element.type); return *this; } @@ -216,11 +216,11 @@ std::string docpp::HTML::Element::get(const int formatting, const int tabc) cons ret += "<" + this->tag; - for (const Property& it : this->properties.getProperties()) { - if (!it.getKey().compare("")) continue; - if (!it.getValue().compare("")) continue; + for (const Property& it : this->properties.get_properties()) { + if (!it.get_key().compare("")) continue; + if (!it.get_value().compare("")) continue; - ret += " " + it.getKey() + "=\"" + it.getValue() + "\""; + ret += " " + it.get_key() + "=\"" + it.get_value() + "\""; } if (this->type != docpp::HTML::TYPE_SELF_CLOSING) { @@ -244,19 +244,19 @@ template T docpp::HTML::Element::get(const int formatting, const in return T(this->get(formatting, tabc)); } -std::string docpp::HTML::Element::getTag() const { +std::string docpp::HTML::Element::get_tag() const { return this->tag; } -template T docpp::HTML::Element::getTag() const { +template T docpp::HTML::Element::get_tag() const { return T(this->tag); } -std::string docpp::HTML::Element::getData() const { +std::string docpp::HTML::Element::get_data() const { return this->data; } -template T docpp::HTML::Element::getData() const { +template T docpp::HTML::Element::get_data() const { return T(this->data); } @@ -356,7 +356,7 @@ void docpp::HTML::Section::erase(const size_type index) { void docpp::HTML::Section::erase(const Section& section) { for (size_type i{0}; i < this->size(); i++) { - const Section it = this->getSections().at(i); + const Section it = this->get_sections().at(i); if (it.get() == section.get()) { this->erase(i); @@ -369,7 +369,7 @@ void docpp::HTML::Section::erase(const Section& section) { void docpp::HTML::Section::erase(const Element& element) { for (size_type i{0}; i < this->size(); i++) { - const Element it = this->getElements().at(i); + const Element it = this->get_elements().at(i); if (it.get() == element.get()) { this->erase(i); @@ -413,7 +413,7 @@ docpp::HTML::Section docpp::HTML::Section::at_section(const size_type index) con docpp::HTML::Section::size_type docpp::HTML::Section::find(const Element& element) { for (size_type i{0}; i < this->size(); i++) { - const Element it = this->getElements().at(i); + const Element it = this->get_elements().at(i); if (it.get() == element.get()) { return i; @@ -425,7 +425,7 @@ docpp::HTML::Section::size_type docpp::HTML::Section::find(const Element& elemen docpp::HTML::Section::size_type docpp::HTML::Section::find(const Section& section) { for (size_type i{0}; i < this->size(); i++) { - const Section it = this->getSections().at(i); + const Section it = this->get_sections().at(i); if (it.get() == section.get()) { return i; @@ -436,7 +436,7 @@ docpp::HTML::Section::size_type docpp::HTML::Section::find(const Section& sectio } docpp::HTML::Section::size_type docpp::HTML::Section::find(const std::string& str) { - const std::vector elements = this->getElements(); + const std::vector elements = this->get_elements(); for (size_type i{0}; i < elements.size(); i++) { if (!elements.at(i).get().compare(str)) { @@ -444,7 +444,7 @@ docpp::HTML::Section::size_type docpp::HTML::Section::find(const std::string& st } } - const std::vector
sections = this->getSections(); + const std::vector
sections = this->get_sections(); for (size_type i{0}; i < sections.size(); i++) { if (!sections.at(i).get().compare(str)) { @@ -491,7 +491,7 @@ docpp::HTML::Section::size_type docpp::HTML::Section::size() const { return this->index; } -std::vector docpp::HTML::Section::getElements() const { +std::vector docpp::HTML::Section::get_elements() const { std::vector ret{}; ret.reserve(this->index); for (size_type i{0}; i < this->index; i++) { @@ -502,7 +502,7 @@ std::vector docpp::HTML::Section::getElements() const { return std::move(ret); } -std::vector docpp::HTML::Section::getSections() const { +std::vector docpp::HTML::Section::get_sections() const { std::vector ret{}; ret.reserve(this->index); @@ -536,11 +536,11 @@ std::string docpp::HTML::Section::get(const int formatting, const int tabc) cons if (this->tag.compare("")) { ret += "<" + this->tag; - for (const Property& it : this->properties.getProperties()) { - if (!it.getKey().compare("")) continue; - if (!it.getValue().compare("")) continue; + for (const Property& it : this->properties.get_properties()) { + if (!it.get_key().compare("")) continue; + if (!it.get_value().compare("")) continue; - ret += " " + it.getKey() + "=\"" + it.getValue() + "\""; + ret += " " + it.get_key() + "=\"" + it.get_value() + "\""; } ret += ">"; @@ -603,7 +603,7 @@ template T docpp::HTML::Document::get(const int formatting, const i return T(this->get(formatting, tabc)); } -docpp::HTML::Section& docpp::HTML::Document::getSection() { +docpp::HTML::Section& docpp::HTML::Document::get_section() { return this->document; } @@ -611,13 +611,13 @@ void docpp::HTML::Document::set(const docpp::HTML::Section& document) { this->document = document; } -void docpp::HTML::Document::setDoctype(const std::string& doctype) { +void docpp::HTML::Document::set_doctype(const std::string& doctype) { this->doctype = doctype; } docpp::HTML::Document docpp::HTML::Document::operator=(const docpp::HTML::Document& document) { this->set(document.get()); - this->setDoctype(document.getDoctype()); + this->set_doctype(document.get_doctype()); return *this; } @@ -628,14 +628,14 @@ docpp::HTML::Document docpp::HTML::Document::operator=(const docpp::HTML::Sectio docpp::HTML::Document::Document(const docpp::HTML::Section& document, const std::string& doctype) { this->set(document); - this->setDoctype(doctype); + this->set_doctype(doctype); } -std::string docpp::HTML::Document::getDoctype() const { +std::string docpp::HTML::Document::get_doctype() const { return this->doctype; } -template T docpp::HTML::Document::getDoctype() const { +template T docpp::HTML::Document::get_doctype() const { return T(this->doctype); } @@ -647,19 +647,19 @@ docpp::CSS::Property::Property(const std::pair& proper this->set(property); } -std::string docpp::CSS::Property::getKey() const { +std::string docpp::CSS::Property::get_key() const { return this->property.first; } -template T docpp::CSS::Property::getKey() const { +template T docpp::CSS::Property::get_key() const { return T(this->property.first); } -std::string docpp::CSS::Property::getValue() const { +std::string docpp::CSS::Property::get_value() const { return this->property.second; } -template T docpp::CSS::Property::getValue() const { +template T docpp::CSS::Property::get_value() const { return T(this->property.second); } @@ -671,11 +671,11 @@ template std::pair docpp::CSS::Property::get() const { return std::pair(this->property.first, this->property.second); } -void docpp::CSS::Property::setKey(const std::string& key) { +void docpp::CSS::Property::set_key(const std::string& key) { this->property.first = key; } -void docpp::CSS::Property::setValue(const std::string& value) { +void docpp::CSS::Property::set_value(const std::string& value) { this->property.second = value; } @@ -706,7 +706,7 @@ docpp::CSS::Element::Element(const std::pair> } docpp::CSS::Element docpp::CSS::Element::operator=(const docpp::CSS::Element& element) { - this->set({element.getTag(), element.getProperties()}); + this->set({element.get_tag(), element.get_properties()}); return *this; } @@ -771,7 +771,7 @@ docpp::CSS::Element::size_type docpp::CSS::Element::find(const Property& propert docpp::CSS::Element::size_type docpp::CSS::Element::find(const std::string& str) { 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).get_key().compare(str) || !this->element.second.at(i).get_value().compare(str)) { return i; } } @@ -814,8 +814,8 @@ std::string docpp::CSS::Element::get(const int formatting, const int tabc) const } for (const Property& it : this->element.second) { - if (!it.getKey().compare("")) continue; - if (!it.getValue().compare("")) continue; + if (!it.get_key().compare("")) continue; + if (!it.get_value().compare("")) continue; if (formatting == docpp::CSS::FORMATTING_PRETTY) { for (size_type i{0}; i < tabc + 1; i++) { @@ -823,7 +823,7 @@ std::string docpp::CSS::Element::get(const int formatting, const int tabc) const } } - ret += it.getKey() + ": " + it.getValue() + ";"; + ret += it.get_key() + ": " + it.get_value() + ";"; if (formatting == docpp::CSS::FORMATTING_PRETTY || formatting == docpp::CSS::FORMATTING_NEWLINE) { ret += "\n"; @@ -844,15 +844,15 @@ template T docpp::CSS::Element::get(const int formatting, const int return T(this->get(formatting, tabc)); } -std::string docpp::CSS::Element::getTag() const { +std::string docpp::CSS::Element::get_tag() const { return this->element.first; } -template T docpp::CSS::Element::getTag() const { +template T docpp::CSS::Element::get_tag() const { return T(this->element.first); } -std::vector docpp::CSS::Element::getProperties() const { +std::vector docpp::CSS::Element::get_properties() const { return this->element.second; } @@ -889,7 +889,7 @@ void docpp::CSS::Stylesheet::erase(const size_type index) { } docpp::CSS::Stylesheet docpp::CSS::Stylesheet::operator=(const docpp::CSS::Stylesheet& stylesheet) { - this->set(stylesheet.getElements()); + this->set(stylesheet.get_elements()); return *this; } @@ -921,7 +921,7 @@ docpp::CSS::Stylesheet::size_type docpp::CSS::Stylesheet::find(const Element& el docpp::CSS::Stylesheet::size_type docpp::CSS::Stylesheet::find(const std::string& str) { 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).get_tag().compare(str)) { return i; } } @@ -953,7 +953,7 @@ void docpp::CSS::Stylesheet::swap(const Element& element1, const Element& elemen this->swap(this->find(element1), this->find(element2)); } -std::vector docpp::CSS::Stylesheet::getElements() const { +std::vector docpp::CSS::Stylesheet::get_elements() const { return this->elements; } diff --git a/tests/test.cpp b/tests/test.cpp index 9691dfb..2e96dd4 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -252,8 +252,8 @@ SCENARIO("Test HTML", "[HTML]") { const int pos2 = prop.find("class2"); - REQUIRE(prop.at(pos2).getKey() == "class"); - REQUIRE(prop.at(pos2).getValue() == "class1 class2 class3"); + REQUIRE(prop.at(pos2).get_key() == "class"); + REQUIRE(prop.at(pos2).get_value() == "class1 class2 class3"); REQUIRE(pos2 != docpp::HTML::Properties::npos); @@ -269,17 +269,17 @@ SCENARIO("Test HTML", "[HTML]") { const auto test16 = []() { docpp::HTML::Document doc = docpp::HTML::Section({}); - 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.get_section().push_back(docpp::HTML::Element("p", {}, "Test 1")); + doc.get_section().push_back(docpp::HTML::Element("p", {}, "Test 2")); + doc.get_section().push_back(docpp::HTML::Element("p", {}, "Test 3")); - doc.getSection() = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {}); + doc.get_section() = docpp::HTML::Section(docpp::HTML::SECTION_HTML, {}); - 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.get_section().push_back(docpp::HTML::Element("p", {}, "Test 4")); + doc.get_section().push_back(docpp::HTML::Element("p", {}, "Test 5")); + doc.get_section().push_back(docpp::HTML::Element("p", {}, "Test 6")); - doc.getSection() += docpp::HTML::Element("p", {}, "Test 7"); + doc.get_section() += docpp::HTML::Element("p", {}, "Test 7"); REQUIRE(doc.get() == "

Test 4

Test 5

Test 6

Test 7

"); }; @@ -325,14 +325,14 @@ SCENARIO("Test HTML", "[HTML]") { prop.push_back(docpp::HTML::Property(std::pair("style", "color: red; font-size: 16px; font-family: Arial;"))); for (const docpp::HTML::Property& p : prop) { - REQUIRE(p.getKey() == "id"); - REQUIRE(p.getValue() == "test_id"); + REQUIRE(p.get_key() == "id"); + REQUIRE(p.get_value() == "test_id"); break; } for (docpp::HTML::Properties::iterator it = ++prop.begin(); it != prop.end(); ++it) { - REQUIRE(it->getKey() == "class"); - REQUIRE(it->getValue() == "class1 class2 class3"); + REQUIRE(it->get_key() == "class"); + REQUIRE(it->get_value() == "class1 class2 class3"); break; } };