Change the behavior of find() functions. They no longer throw an

exception, but rather return npos (-1).
This commit is contained in:
Jacob 2024-05-06 02:28:23 +02:00
parent 8a8313a01c
commit 8f1f175138
2 changed files with 43 additions and 3 deletions

View file

@ -43,6 +43,11 @@ namespace docpp {
std::pair<std::string, std::string> property{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Construct a new HTMLProperty object
* @param key The key of the property
@ -96,6 +101,11 @@ namespace docpp {
std::vector<HTMLProperty> properties{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Get the properties of the element
* @return std::vector<HTMLProperty> The properties of the element
@ -138,6 +148,11 @@ namespace docpp {
HTMLElementProperties properties{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Construct a new HTMLElement object
* @param tag The tag of the element
@ -189,6 +204,11 @@ namespace docpp {
std::unordered_map<int, HTMLSection> sections{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Prepend an element to the section
* @param element The element to add
@ -330,6 +350,11 @@ namespace docpp {
HTMLSection document{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Get the document
* @param std::string The type to return
@ -376,6 +401,11 @@ namespace docpp {
std::pair<std::string, std::string> property{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Construct a new CSSProperty object
* @param key The key of the property
@ -432,6 +462,11 @@ namespace docpp {
std::pair<std::string, std::vector<CSSProperty>> element{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Construct a new CSSElement object
* @param tag The tag of the element
@ -485,6 +520,11 @@ namespace docpp {
std::vector<CSSElement> elements{};
protected:
public:
/**
* @brief The npos value
*/
static const int npos = -1;
/**
* @brief Construct a new CSSStylesheet object
* @param elements The elements to set

View file

@ -252,7 +252,7 @@ int docpp::HTML::HTMLSection::find(const HTMLElement& element) {
}
}
throw std::out_of_range("Element not found");
return docpp::HTML::HTMLSection::npos;
}
int docpp::HTML::HTMLSection::find(const HTMLSection& section) {
@ -264,7 +264,7 @@ int docpp::HTML::HTMLSection::find(const HTMLSection& section) {
}
}
throw std::out_of_range("Section not found");
return docpp::HTML::HTMLSection::npos;
}
int docpp::HTML::HTMLSection::size() const {
@ -504,7 +504,7 @@ int docpp::CSS::CSSStylesheet::find(const CSSElement& element) {
}
}
throw std::out_of_range("Element not found");
return docpp::CSS::CSSStylesheet::npos;
}
int docpp::CSS::CSSStylesheet::size() const {