diff --git a/src/string_utils.cpp b/src/string_utils.cpp index 9a2a9bf0e40af6d4818e36f281765699b9c6ee22..801261fd05ddc998d5f52b354ae8113aef14a19a 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -22,6 +22,7 @@ #include "string_utils.h" #include <fmt/core.h> +#include <fmt/ranges.h> #include <sstream> #include <cctype> @@ -146,14 +147,9 @@ string_remove_suffix(std::string_view str, char separator) } std::string -string_join(std::set<std::string> set, std::string_view separator) +string_join(const std::set<std::string>& set, std::string_view separator) { - if (set.empty()) - return ""; - std::string output; - for (const auto &s : set) - output += s+separator; - return output; + return fmt::format("{}", fmt::join(set, separator)); } std::set<std::string> diff --git a/src/string_utils.h b/src/string_utils.h index b2b10c4b7bafee3cc62e85565eec37b3f675ed7f..c229638345d6e2acf614f0bacca3e1f3425bd449 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -178,7 +178,7 @@ void string_replace(std::string& str, const std::string& from, const std::string std::string_view string_remove_suffix(std::string_view str, char separator); -std::string string_join(std::set<std::string> set, std::string_view separator = "/"); +std::string string_join(const std::set<std::string>& set, std::string_view separator = "/"); std::set<std::string> string_split_set(std::string& str, std::string_view separator = "/");