# HG changeset patch # User David Demelier # Date 1531739650 -7200 # Node ID 34af864668fa0ad87f2f4b50399c919e5264926f # Parent fbb0c95724c3ad175f42f820270aa30c16cde58e Core: use more C++17 diff -r fbb0c95724c3 -r 34af864668fa irccdctl/rule_add_cli.cpp --- a/irccdctl/rule_add_cli.cpp Tue Jul 10 21:44:00 2018 +0200 +++ b/irccdctl/rule_add_cli.cpp Mon Jul 16 13:14:10 2018 +0200 @@ -74,7 +74,7 @@ } // Index. - boost::optional index; + std::optional index; if (result.count("-i") > 0 && !(index = to_uint(result.find("-i")->second))) throw std::invalid_argument("invalid index argument"); diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/acceptor.hpp --- a/libirccd-core/irccd/acceptor.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/acceptor.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -28,9 +28,7 @@ #include #include -namespace irccd { - -namespace io { +namespace irccd::io { class stream; @@ -70,8 +68,6 @@ virtual void accept(accept_handler handler) = 0; }; -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_ACCEPTOR_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/connector.hpp --- a/libirccd-core/irccd/connector.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/connector.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -28,9 +28,7 @@ #include #include -namespace irccd { - -namespace io { +namespace irccd::io { class stream; @@ -72,8 +70,6 @@ virtual void connect(connect_handler handler) = 0; }; -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_CONNECTOR_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/fs_util.hpp --- a/libirccd-core/irccd/fs_util.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/fs_util.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -29,12 +29,10 @@ #include -namespace irccd { - /** * \brief Filesystem utilities. */ -namespace fs_util { +namespace irccd::fs_util { // {{{ base_name @@ -142,8 +140,6 @@ // }}} -} // !fs_util - -} // !irccd +} // !irccd::fs_util #endif // !IRCCD_COMMON_FS_UTIL_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/ini_util.hpp --- a/libirccd-core/irccd/ini_util.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/ini_util.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -24,7 +24,7 @@ * \brief Ini utilities. */ -#include +#include #include "ini.hpp" #include "string_util.hpp" @@ -44,7 +44,7 @@ * \return the value or none if not able to convert */ template -inline boost::optional get_uint(const ini::section& sc, const std::string& name) noexcept +inline std::optional get_uint(const ini::section& sc, const std::string& name) noexcept { return string_util::to_uint(sc.get(name).value()); } @@ -78,7 +78,7 @@ * \return the value or none if not able to convert */ template -inline boost::optional optional_uint(const ini::section& sc, +inline std::optional optional_uint(const ini::section& sc, const std::string& name, Int def) noexcept { diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/socket_acceptor.hpp --- a/libirccd-core/irccd/socket_acceptor.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/socket_acceptor.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -29,9 +29,7 @@ #include "acceptor.hpp" #include "socket_stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief Socket stream acceptor interface. @@ -155,8 +153,6 @@ #endif -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_SOCKET_ACCEPTOR_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/socket_connector.hpp --- a/libirccd-core/irccd/socket_connector.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/socket_connector.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -31,9 +31,7 @@ #include "connector.hpp" #include "socket_stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief Socket connection interface. @@ -169,8 +167,6 @@ #endif -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_SOCKET_CONNECTOR_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/socket_stream.hpp --- a/libirccd-core/irccd/socket_stream.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/socket_stream.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -36,9 +36,7 @@ #include "stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \cond HIDDEN_SYMBOLS @@ -239,8 +237,6 @@ #endif -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_SOCKET_STREAM_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/stream.hpp --- a/libirccd-core/irccd/stream.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/stream.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -29,9 +29,7 @@ #include "json.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief Read completion handler. @@ -84,8 +82,6 @@ virtual void write(const nlohmann::json& json, write_handler handler) = 0; }; -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_COMMON_STREAM_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/string_util.cpp --- a/libirccd-core/irccd/string_util.cpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/string_util.cpp Mon Jul 16 13:14:10 2018 +0200 @@ -30,6 +30,7 @@ #include #include +#include #include "string_util.hpp" @@ -43,7 +44,7 @@ namespace { -const std::unordered_map irc_colors{ +const std::unordered_map irc_colors{ { "white", 0 }, { "black", 1 }, { "blue", 2 }, @@ -62,7 +63,7 @@ { "lightgrey", 15 } }; -const std::unordered_map irc_attributes{ +const std::unordered_map irc_attributes{ { "bold", '\x02' }, { "italic", '\x09' }, { "strike", '\x13' }, @@ -72,7 +73,7 @@ { "reverse", '\x16' } }; -const std::unordered_map shell_colors{ +const std::unordered_map shell_colors{ { "black", 30 }, { "red", 31 }, { "green", 32 }, @@ -84,7 +85,7 @@ { "default", 39 }, }; -const std::unordered_map shell_attributes{ +const std::unordered_map shell_attributes{ { "bold", 1 }, { "dim", 2 }, { "underline", 4 }, @@ -93,12 +94,12 @@ { "hidden", 8 } }; -inline bool is_reserved(char token) noexcept +auto is_reserved(char token) noexcept -> bool { return token == '#' || token == '@' || token == '$' || token == '!'; } -std::string subst_date(const std::string& text, const subst& params) +auto subst_date(const std::string& text, const subst& params) -> std::string { std::ostringstream oss; @@ -119,9 +120,9 @@ return oss.str(); } -std::string subst_keywords(const std::string& content, const subst& params) +auto subst_keywords(const std::string& content, const subst& params) -> std::string { - auto value = params.keywords.find(content); + auto value = params.keywords.find(std::string(content)); if (value != params.keywords.end()) return value->second; @@ -383,7 +384,7 @@ std::string strip(std::string str) noexcept { - const auto test = [] (auto c) { return !std::isspace(c); }; + const auto test = [] (auto c) noexcept { return !std::isspace(c); }; str.erase(str.begin(), std::find_if(str.begin(), str.end(), test)); str.erase(std::find_if(str.rbegin(), str.rend(), test).base(), str.end()); @@ -395,7 +396,7 @@ // {{{ split -std::vector split(const std::string& list, const std::string& delimiters, int max) +auto split(std::string_view list, const std::string& delimiters, int max) -> std::vector { std::vector result; std::size_t next = -1, current; @@ -428,11 +429,22 @@ // }}} +// {{{ is_identifier + +auto is_identifier(std::string_view name) noexcept -> bool +{ + static const std::regex regex("[A-Za-z0-9-_]+"); + + return std::regex_match(std::string(name), regex); +} + +// }}} + // {{{ is_boolean -bool is_boolean(std::string value) noexcept +auto is_boolean(std::string value) noexcept -> bool { - std::transform(value.begin(), value.end(), value.begin(), [] (auto c) { + std::transform(value.begin(), value.end(), value.begin(), [] (auto c) noexcept { return toupper(c); }); diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/string_util.hpp --- a/libirccd-core/irccd/string_util.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/string_util.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -29,23 +29,20 @@ #include #include #include -#include +#include #include #include #include +#include #include #include #include -#include - -namespace irccd { /** - * \file string_util.hpp * \brief String utilities. */ -namespace string_util { +namespace irccd::string_util { // {{{ subst @@ -190,7 +187,7 @@ * - \@{white,black,bold,underline}: will write white text on * black in both bold and underline. */ -std::string format(std::string text, const subst& params = {}); +auto format(std::string text, const subst& params = {}) -> std::string; // }}} @@ -202,7 +199,7 @@ * \param str the string * \return the removed white spaces */ -std::string strip(std::string str) noexcept; +auto strip(std::string str) noexcept -> std::string; // }}} @@ -216,7 +213,7 @@ * \param max max number of split * \return a list of string splitted */ -std::vector split(const std::string& list, const std::string& delimiters, int max = -1); +auto split(std::string_view list, const std::string& delimiters, int max = -1) -> std::vector; // }}} @@ -231,7 +228,7 @@ * \return the string */ template -std::string join(InputIt first, InputIt last, DelimType delim = ':') +auto join(InputIt first, InputIt last, DelimType delim = ':') -> std::string { std::ostringstream oss; @@ -253,7 +250,7 @@ * \return the string */ template -std::string join(const Container& c, DelimType delim = ':') +auto join(const Container& c, DelimType delim = ':') -> std::string { return join(c.begin(), c.end(), delim); } @@ -266,7 +263,7 @@ * \return the string */ template -inline std::string join(std::initializer_list list, DelimType delim = ':') +auto join(std::initializer_list list, DelimType delim = ':') -> std::string { return join(list.begin(), list.end(), delim); } @@ -281,10 +278,7 @@ * \param name the identifier name * \return true if is valid */ -inline bool is_identifier(const std::string& name) -{ - return std::regex_match(name, std::regex("[A-Za-z0-9-_]+")); -} +auto is_identifier(std::string_view name) noexcept -> bool; // }}} @@ -297,7 +291,7 @@ * \return true if is boolean * \note this function is case-insensitive */ -bool is_boolean(std::string value) noexcept; +auto is_boolean(std::string value) noexcept -> bool; // }}} @@ -336,7 +330,7 @@ * \return the string */ template -std::string sprintf(const Format& format, const Args&... args) +auto sprintf(const Format& format, const Args&... args) -> std::string { boost::format fmter(format); @@ -358,9 +352,9 @@ * \return the value or boost::none if not convertible */ template -boost::optional to_int(const std::string& str, - T min = std::numeric_limits::min(), - T max = std::numeric_limits::max()) noexcept +auto to_int(const std::string& str, + T min = std::numeric_limits::min(), + T max = std::numeric_limits::max()) noexcept -> std::optional { static_assert(std::is_signed::value, "must be signed"); @@ -368,7 +362,7 @@ auto v = std::strtoll(str.c_str(), &end, 10); if (*end != '\0' || v < min || v > max) - return boost::none; + return std::nullopt; return static_cast(v); } @@ -387,9 +381,9 @@ * \return the value or boost::none if not convertible */ template -boost::optional to_uint(const std::string& str, - T min = std::numeric_limits::min(), - T max = std::numeric_limits::max()) noexcept +auto to_uint(const std::string& str, + T min = std::numeric_limits::min(), + T max = std::numeric_limits::max()) noexcept -> std::optional { static_assert(std::is_unsigned::value, "must be unsigned"); @@ -397,15 +391,13 @@ auto v = std::strtoull(str.c_str(), &end, 10); if (*end != '\0' || v < min || v > max) - return boost::none; + return std::nullopt; return static_cast(v); } // }}} -} // !string_util - -} // !irccd +} // !irccd::string_util #endif // !IRCCD_COMMON_STRING_UTIL_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/system.cpp --- a/libirccd-core/irccd/system.cpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/system.cpp Mon Jul 16 13:14:10 2018 +0200 @@ -58,9 +58,7 @@ #include "string_util.hpp" #include "xdg.hpp" -namespace irccd { - -namespace sys { +namespace irccd::sys { namespace { @@ -500,6 +498,4 @@ // }}} -} // !sys - -} // !irccd +} // !irccd::sys diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/system.hpp --- a/libirccd-core/irccd/system.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/system.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -33,12 +33,10 @@ #include "sysconfig.hpp" -namespace irccd { - /** * \brief Namespace for system functions. */ -namespace sys { +namespace irccd::sys { /** * Set the program name, needed for some functions or some systems. @@ -160,8 +158,6 @@ std::vector plugin_filenames(const std::string& name, const std::vector& extensions); -} // !sys - -} // !irccd +} // !irccd::sys #endif // !IRCCD_COMMON_SYSTEM_HPP diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/tls_acceptor.hpp --- a/libirccd-core/irccd/tls_acceptor.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/tls_acceptor.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -31,9 +31,7 @@ #include "socket_acceptor.hpp" #include "tls_stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief TLS/SSL acceptors. @@ -87,9 +85,7 @@ }); } -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_HAVE_SSL diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/tls_connector.hpp --- a/libirccd-core/irccd/tls_connector.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/tls_connector.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -31,9 +31,7 @@ #include "socket_connector.hpp" #include "tls_stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief TLS/SSL connectors. @@ -86,9 +84,7 @@ }); } -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_HAVE_SSL diff -r fbb0c95724c3 -r 34af864668fa libirccd-core/irccd/tls_stream.hpp --- a/libirccd-core/irccd/tls_stream.hpp Tue Jul 10 21:44:00 2018 +0200 +++ b/libirccd-core/irccd/tls_stream.hpp Mon Jul 16 13:14:10 2018 +0200 @@ -32,9 +32,7 @@ #include "socket_stream.hpp" -namespace irccd { - -namespace io { +namespace irccd::io { /** * \brief TLS/SSL streams. @@ -55,9 +53,7 @@ } }; -} // !io - -} // !irccd +} // !irccd::io #endif // !IRCCD_HAVE_SSL