libdnf5::utils
-
template<typename ...Args>
inline std::string libdnf5::utils::sformat(std::string_view runtime_format_string, Args&&... args) Format
args
according to theruntime_format_string
, and return the result as a string. Unlike C++20std::format
, the format string of thelibdnf5::sformat
function template does not have to be a constant expression.
-
template<typename ...Args>
std::string libdnf5::utils::format(bool translate, BgettextMessage format_string, unsigned long plural_form, Args&&... args) Format
args
according to theformat_string
, and return the result as a string.- Parameters:
translate – If
true
, it will attempt to translate the message to the requested locale.format_string – message contains formating string
plural_form – number is used to select the appropriate plural form of the format string
args – arguments to be formated
- Returns:
A string object holding the formatted result.
-
template<typename ...Args>
std::string libdnf5::utils::format(const Locale *locale, bool translate, BgettextMessage format_string, unsigned long plural_form, Args&&... args) Format
args
according to theformat_string
, and return the result as a string.- Parameters:
locale – requested locale for translation and argument formating, nullptr = use global/thread locale
translate – If
true
, it will attempt to translate the message to the requested locale.format_string – message contains formating string
plural_form – number is used to select the appropriate plural form of the format string
args – arguments to be formated
- Returns:
A string object holding the formatted result.
- LIBDNF_API bool libdnf5::utils::is_glob_pattern (const char *pattern) noexcept
Check if a given pattern is a GLOB.
- Parameters:
pattern – Text pattern to be test
- Returns:
True if a given pattern is a GLOB
- LIBDNF_API bool libdnf5::utils::is_file_pattern (const std::string &pattern) noexcept
Check if a given pattern is a file path.
- Parameters:
pattern – Text pattern to be test
- Returns:
True if a given pattern is a file path
-
template<class Enum>
constexpr std::underlying_type_t<Enum> libdnf5::utils::to_underlying(Enum e) noexcept Converts an enumeration to its underlying type.
std::to_underlying
is planned for C++23.
-
class Locale
- #include <locale.hpp>
Class for passing locale.
Public Functions
-
explicit Locale(const char *std_name)
Creates a new
Locale
object containing the system locale with the specifiedstd_name
(for example, “C”, or “POSIX”, or “cs_CZ.UTF-8”) if such a locale is supported by the operating system.- Parameters:
std_name – name of the system locale to use (”” - user-preferred locale, must not be null pointer)
-
~Locale()
-
const std::locale &get_cpp_locale() const
-
::locale_t get_c_locale() const
-
explicit Locale(const char *std_name)
-
class Locker
- #include <locker.hpp>
Object for implementing a simple file mutex mechanism or checking read/write access on a given path.
Public Functions
-
~Locker()
-
bool read_lock()
Try to acquire read lock on a given file path.
- Throws:
libdnf5::SystemError – if an unexpected error occurs when checking the lock state, like insufficient privileges
- Returns:
True if lock acquisition was successful, otherwise false
-
bool write_lock()
Try to acquire write lock on a given file path.
- Throws:
libdnf5::SystemError – if an unexpected error occurs when checking the lock state, like insufficient privileges
- Returns:
True if lock acquisition was successful, otherwise false
-
void unlock()
Unlock the existing lock and remove the underlying lock file.
- Throws:
libdnf5::SystemError – if an unexpected error occurs when unlocking
-
~Locker()
-
class OSRelease
- #include <os_release.hpp>
Object which loads and exposes values from an os-release file.
Public Functions
-
inline explicit OSRelease(std::filesystem::path path = "/etc/os-release")
Creates an instance of
OSRelease
from the file atpath
.- Parameters:
path – The path to the os-release file to load and parse.
-
std::string get_value(const std::string &key, const std::string &default_value = "UNSET")
Returns the corresponding os-release value for
key
. If the value forkey
isn’t set,default_value
is returned.- Parameters:
key – The os-release key to get the value of.
default_value – Default value to return if the value for
key
isn’t set.
-
bool contains(const std::string &key)
Returns whether the corresponding os-release value is set for
key
.- Parameters:
key – The os-release key to check if set.
-
inline explicit OSRelease(std::filesystem::path path = "/etc/os-release")