lib/utils: small cleanups

Fix some static analysis warnings
This commit is contained in:
Dirk-Jan C. Binnema
2026-04-10 00:12:50 +03:00
committed by Seth Ladygo
parent d8afabcc0f
commit 6715ff418a
5 changed files with 33 additions and 28 deletions

View File

@ -218,7 +218,7 @@ utf8_flatten(const std::string& s) {
*
* @return a cleaned-up string.
*/
std::string utf8_clean(const std::string& dirty);
[[nodiscard]] std::string utf8_clean(const std::string& dirty);
/**
@ -228,7 +228,7 @@ std::string utf8_clean(const std::string& dirty);
*
* @return string
*/
std::string utf8_wordbreak(const std::string& txt);
[[nodiscard]] std::string utf8_wordbreak(const std::string& txt);
/**
@ -239,7 +239,7 @@ std::string utf8_wordbreak(const std::string& txt);
*
* @return the string without control characters
*/
std::string remove_ctrl(const std::string& str);
[[nodiscard]] std::string remove_ctrl(const std::string& str);
/**
* Split a string in parts. As a special case, splitting an empty string
@ -250,7 +250,8 @@ std::string remove_ctrl(const std::string& str);
*
* @return the parts.
*/
std::vector<std::string> split(const std::string& str, const std::string& sepa);
[[nodiscard]] std::vector<std::string> split(const std::string& str,
const std::string& sepa);
/**
* Split a string in parts. As a special case, splitting an empty string
@ -271,8 +272,10 @@ std::vector<std::string> split(const std::string& str, char sepa);
*
* @return string
*/
std::string join(const std::vector<std::string>& svec, const std::string& sepa);
static inline std::string join(const std::vector<std::string>& svec, char sepa) {
[[nodiscard]] std::string join(const std::vector<std::string>& svec,
const std::string& sepa);
[[nodiscard]] static inline std::string join(const std::vector<std::string>& svec,
char sepa) {
return join(svec, std::string(1, sepa));
}
@ -314,7 +317,7 @@ static inline bool mu_print_encoded(fmt::format_string<T...> frm, T&&... args) n
*/
constexpr ::time_t time_t_min = 0;
constexpr ::time_t time_t_max = std::numeric_limits<::time_t>::max();
constexpr ::time_t to_time_t(int64_t t) {
[[nodiscard]] constexpr ::time_t to_time_t(int64_t t) {
return std::clamp(t,
static_cast<int64_t>(time_t_min),
static_cast<int64_t>(time_t_max));
@ -333,7 +336,8 @@ constexpr ::time_t to_time_t(int64_t t) {
*
* @return the corresponding time_t or Nothing if parsing failed.
*/
Option<::time_t> parse_date_time(const std::string& date, bool first, bool use_utc=false);
[[nodiscard]] Option<::time_t> parse_date_time(const std::string& date,
bool first, bool use_utc=false);
/**
* Crudely convert HTML to plain text. This attempts to scrape the
@ -343,7 +347,7 @@ Option<::time_t> parse_date_time(const std::string& date, bool first, bool use_u
*
* @return plain text
*/
std::string html_to_text(const std::string& html);
[[nodiscard]] std::string html_to_text(const std::string& html);
/**
* Hack to avoid locale crashes