# HG changeset patch # User David Demelier # Date 1531162920 -7200 # Node ID fff3ee62d0fc41eb3ae4bc66df3644d20f381838 # Parent 16e83b636cb81692cc97d341799f661f1d972ce0 Common: use more C++17 diff -r 16e83b636cb8 -r fff3ee62d0fc libirccd-core/irccd/config.cpp --- a/libirccd-core/irccd/config.cpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/config.cpp Mon Jul 09 21:02:00 2018 +0200 @@ -18,13 +18,12 @@ #include -#include - #include "config.hpp" +#include "system.hpp" namespace irccd { -boost::optional config::search(const std::string& name) +auto config::search(std::string_view name) -> std::optional { for (const auto& path : sys::config_filenames(name)) { boost::system::error_code ec; @@ -33,7 +32,18 @@ return config(path); } - return boost::optional(); + return std::nullopt; +} + +config::config(std::string path) + : document(path.empty() ? ini::document() : ini::read_file(path)) + , path_(std::move(path)) +{ +} + +auto config::get_path() const noexcept -> const std::string& +{ + return path_; } } // !irccd diff -r 16e83b636cb8 -r fff3ee62d0fc libirccd-core/irccd/config.hpp --- a/libirccd-core/irccd/config.hpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/config.hpp Mon Jul 09 21:02:00 2018 +0200 @@ -24,7 +24,8 @@ * \brief Read .ini configuration file for irccd */ -#include +#include +#include #include "ini.hpp" @@ -44,28 +45,21 @@ * \param name the file name * \return the config or empty if not found */ - static boost::optional search(const std::string& name); + static auto search(std::string_view name) -> std::optional; /** * Load the configuration from the specified path. * * \param path the path */ - inline config(std::string path = "") - : document(path.empty() ? ini::document() : ini::read_file(path)) - , path_(std::move(path)) - { - } + config(std::string path = ""); /** * Get the path to the configuration file. * * \return the path */ - inline const std::string& get_path() const noexcept - { - return path_; - } + auto get_path() const noexcept -> const std::string&; }; } // !irccd diff -r 16e83b636cb8 -r fff3ee62d0fc libirccd-core/irccd/system.cpp --- a/libirccd-core/irccd/system.cpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/system.cpp Mon Jul 09 21:02:00 2018 +0200 @@ -468,11 +468,14 @@ // {{{ config_filenames -std::vector config_filenames(std::string file) +std::vector config_filenames(std::string_view file) { + // TODO: remove this once we can use std::filesystem. + const std::string filename(file); + return { - (user_config_directory() / file).string(), - (sysconfdir() / file).string() + (user_config_directory() / filename).string(), + (sysconfdir() / filename).string() }; } diff -r 16e83b636cb8 -r fff3ee62d0fc libirccd-core/irccd/system.hpp --- a/libirccd-core/irccd/system.hpp Mon Jul 09 20:53:00 2018 +0200 +++ b/libirccd-core/irccd/system.hpp Mon Jul 09 21:02:00 2018 +0200 @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -148,7 +149,7 @@ * \param file the filename to append for convenience * \return the list of paths to check in order */ -std::vector config_filenames(std::string file); +std::vector config_filenames(std::string_view file); /** * Construct a list of paths for reading plugins.