[vcpkg] Collapse join() overloads into a single template.
MODIFY
include/vcpkg_Strings.h
include/vcpkg_Strings.h
@@ -74,15 +74,18 @@ namespace vcpkg::Strings
std::string ascii_to_lowercase(const std::string& input);
- template <class T, class Transformer>
- std::string join(const std::string& delimiter, const std::vector<T>& v, Transformer transformer)
+ template <class T, class Transformer, class CharType>
+ std::basic_string<CharType> join(
+ const CharType* delimiter,
+ const std::vector<T>& v,
+ Transformer transformer)
{
if (v.empty())
{
- return std::string();
+ return std::basic_string<CharType>();
}
- std::string output;
+ std::basic_string<CharType> output;
size_t size = v.size();
output.append(transformer(v.at(0)));
@@ -95,34 +98,14 @@ namespace vcpkg::Strings
return output;
}
-
- std::string join(const std::string& delimiter, const std::vector<std::string>& v);
-
- template <class T, class Transformer>
- std::wstring wjoin(const std::wstring& delimiter, const std::vector<T>& v, Transformer transformer)
+ template <class T, class CharType>
+ std::basic_string<CharType> join(
+ const CharType* delimiter,
+ const std::vector<T>& v)
{
- if (v.empty())
- {
- return std::wstring();
+ return join(delimiter, v, [](const T& x) -> const T&{ return x; });
}
- std::wstring output;
- size_t size = v.size();
-
- output.append(transformer(v.at(0)));
-
- for (size_t i = 1; i < size; ++i)
- {
- output.append(delimiter);
- output.append(transformer(v.at(i)));
- }
-
- return output;
- }
-
- std::wstring wjoin(const std::wstring& delimiter, const std::vector<std::wstring>& v);
-
-
void trim(std::string* s);
std::string trimmed(const std::string& s);

MODIFY
src/vcpkg_Strings.cpp
src/vcpkg_Strings.cpp
@@ -78,16 +78,6 @@ namespace vcpkg::Strings
return output;
}
- std::string join(const std::string& delimiter, const std::vector<std::string>& v)
- {
- return join(delimiter, v, [](const std::string& p) -> const std::string& { return p; });
- }
-
- std::wstring wjoin(const std::wstring& delimiter, const std::vector<std::wstring>& v)
- {
- return wjoin(delimiter, v, [](const std::wstring& p) -> const std::wstring&{ return p; });
- }
-
void trim(std::string* s)
{
s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end());

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
@@ -222,7 +222,7 @@ namespace vcpkg
std::wstring make_cmake_cmd(const fs::path& cmake_exe, const fs::path& cmake_script, const std::vector<CMakeVariable>& pass_variables)
{
- std::wstring cmd_cmake_pass_variables = Strings::wjoin(L" ", pass_variables, [](auto&& v) { return v.s; });
+ std::wstring cmd_cmake_pass_variables = Strings::join(L" ", pass_variables, [](auto&& v) { return v.s; });
return Strings::wformat(LR"("%s" %s -P "%s")", cmake_exe.native(), cmd_cmake_pass_variables, cmake_script.generic_wstring());
}
}

[vcpkg] Collapse join() overloads into a single template.