Marked some functions noexcept.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
tastytea 2020-01-12 15:27:11 +01:00
parent 7fc19639b1
commit 79c5087ca5
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 79 additions and 49 deletions

View File

@ -61,7 +61,7 @@ public:
* @since 0.1.0 * @since 0.1.0
*/ */
[[nodiscard]] [[nodiscard]]
inline string_view get_hostname() const inline string_view get_hostname() const noexcept
{ {
return _hostname; return _hostname;
} }
@ -74,7 +74,7 @@ public:
* @since 0.1.0 * @since 0.1.0
*/ */
[[nodiscard]] [[nodiscard]]
inline string_view get_baseuri() const inline string_view get_baseuri() const noexcept
{ {
return _baseuri; return _baseuri;
} }
@ -85,7 +85,7 @@ public:
* @since 0.1.0 * @since 0.1.0
*/ */
[[nodiscard]] [[nodiscard]]
inline string_view get_access_token() const inline string_view get_access_token() const noexcept
{ {
return _access_token; return _access_token;
} }
@ -115,7 +115,7 @@ public:
* @since 0.1.0 * @since 0.1.0
*/ */
[[nodiscard]] [[nodiscard]]
uint64_t get_max_chars(); uint64_t get_max_chars() noexcept;
/*! @copydoc CURLWrapper::set_proxy(string_view) /*! @copydoc CURLWrapper::set_proxy(string_view)
* *
@ -136,7 +136,7 @@ public:
* @since 0.1.0 * @since 0.1.0
*/ */
[[nodiscard]] [[nodiscard]]
string_view get_proxy() const string_view get_proxy() const noexcept
{ {
return _proxy; return _proxy;
} }
@ -164,7 +164,7 @@ public:
* *
* @since 0.3.0 * @since 0.3.0
*/ */
vector<string> get_post_formats(); vector<string> get_post_formats() noexcept;
/*! /*!
* @brief Set path to Certificate Authority (CA) bundle. * @brief Set path to Certificate Authority (CA) bundle.
@ -187,7 +187,7 @@ public:
* *
* @since 0.2.1 * @since 0.2.1
*/ */
string_view get_cainfo() string_view get_cainfo() const noexcept
{ {
return _cainfo; return _cainfo;
} }

View File

@ -35,12 +35,15 @@ Instance::Instance(const string_view hostname, const string_view access_token)
, _max_chars{0} , _max_chars{0}
{} {}
uint64_t Instance::get_max_chars() uint64_t Instance::get_max_chars() noexcept
{ {
constexpr uint64_t default_max_chars{500}; constexpr uint64_t default_max_chars{500};
if (_max_chars == 0) if (_max_chars != 0)
{ {
return _max_chars;
}
try try
{ {
debuglog << "Querying " << _hostname << " for max_toot_chars…\n"; debuglog << "Querying " << _hostname << " for max_toot_chars…\n";
@ -75,7 +78,6 @@ uint64_t Instance::get_max_chars()
debuglog << "Unexpected exception: " << e.what() << '\n'; debuglog << "Unexpected exception: " << e.what() << '\n';
return default_max_chars; return default_max_chars;
} }
}
return _max_chars; return _max_chars;
} }
@ -107,7 +109,7 @@ answer_type Instance::get_nodeinfo()
return make_request(http_method::GET, hrefs.back(), {}); return make_request(http_method::GET, hrefs.back(), {});
} }
vector<string> Instance::get_post_formats() vector<string> Instance::get_post_formats() noexcept
{ {
constexpr auto default_value{"text/plain"}; constexpr auto default_value{"text/plain"};
@ -116,6 +118,8 @@ vector<string> Instance::get_post_formats()
return _post_formats; return _post_formats;
} }
try
{
debuglog << "Querying " << _hostname << " for postFormats…\n"; debuglog << "Querying " << _hostname << " for postFormats…\n";
const auto answer{get_nodeinfo()}; const auto answer{get_nodeinfo()};
if (!answer) if (!answer)
@ -144,6 +148,32 @@ vector<string> Instance::get_post_formats()
formats.erase(0, pos + 2); // 2 is the length of: ", formats.erase(0, pos + 2); // 2 is the length of: ",
debuglog << "Found postFormat: " << _post_formats.back() << '\n'; debuglog << "Found postFormat: " << _post_formats.back() << '\n';
} }
}
catch (const std::exception &e)
{
debuglog << "Unexpected exception: " << e.what() << '\n';
return {default_value};
}
return _post_formats;
}
{
debuglog << "Couldn't find metadata.postFormats.\n";
_post_formats = {default_value};
return _post_formats;
}
pos += searchstring.size();
auto endpos{answer.body.find("],", pos)};
string formats{answer.body.substr(pos, endpos - pos)};
debuglog << "Extracted postFormats: " << formats << '\n';
while ((pos = formats.find('"', 1)) != string::npos)
{
_post_formats.push_back(formats.substr(1, pos - 1));
formats.erase(0, pos + 2); // 2 is the length of: ",
debuglog << "Found postFormat: " << _post_formats.back() << '\n';
}
return _post_formats; return _post_formats;
} }