Nuke Joiner. Add wjoin()
MODIFY
include/vcpkg_Strings.h
include/vcpkg_Strings.h
@@ -74,7 +74,7 @@ namespace vcpkg::Strings
std::string ascii_to_lowercase(const std::string& input);
template <class T, class Transformer>
- static std::string join(const std::vector<T>& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix, Transformer transformer)
+ std::string join(const std::string& delimiter, const std::vector<T>& v, Transformer transformer)
{
if (v.empty())
{
@@ -84,7 +84,6 @@ namespace vcpkg::Strings
std::string output;
size_t size = v.size();
- output.append(prefix);
output.append(transformer(v.at(0)));
for (size_t i = 1; i < size; ++i)
@@ -93,35 +92,35 @@ namespace vcpkg::Strings
output.append(transformer(v.at(i)));
}
- output.append(suffix);
return output;
}
- static std::string join(const std::vector<std::string>& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix);
+ std::string join(const std::string& delimiter, const std::vector<std::string>& v);
- class Joiner
+ template <class T, class Transformer>
+ std::wstring wjoin(const std::wstring& delimiter, const std::vector<T>& v, Transformer transformer)
+ {
+ if (v.empty())
{
- public:
- static Joiner on(const std::string& delimiter);
+ return std::wstring();
+ }
- Joiner& prefix(const std::string& prefix);
- Joiner& suffix(const std::string& suffix);
+ std::wstring output;
+ size_t size = v.size();
- std::string join(const std::vector<std::string>& v) const;
+ output.append(transformer(v.at(0)));
- template <class T, class Transformer>
- std::string join(const std::vector<T>& v, Transformer transformer) const
+ for (size_t i = 1; i < size; ++i)
{
- return Strings::join(v, this->m_prefix, this->m_delimiter, this->m_suffix, transformer);
+ output.append(delimiter);
+ output.append(transformer(v.at(i)));
+ }
+
+ return output;
}
- private:
- explicit Joiner(const std::string& delimiter);
+ std::wstring wjoin(const std::wstring& delimiter, const std::vector<std::wstring>& v);
- std::string m_prefix;
- std::string m_delimiter;
- std::string m_suffix;
- };
void trim(std::string* s);

MODIFY
src/SourceParagraph.cpp
src/SourceParagraph.cpp
@@ -53,8 +53,8 @@ namespace vcpkg
const std::vector<std::string> remaining_fields = Maps::extract_keys(fields);
const std::vector<std::string>& valid_fields = get_list_of_valid_fields();
- const std::string remaining_fields_as_string = Strings::Joiner::on("\n ").join(remaining_fields);
- const std::string valid_fields_as_string = Strings::Joiner::on("\n ").join(valid_fields);
+ const std::string remaining_fields_as_string = Strings::join("\n ", remaining_fields);
+ const std::string valid_fields_as_string = Strings::join("\n ", valid_fields);
System::println(System::color::error, "Error: There are invalid fields in the Source Paragraph of %s", this->name);
System::println("The following fields were not expected:\n\n %s\n\n", remaining_fields_as_string);

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -158,7 +158,7 @@ namespace vcpkg::Commands::Install
triplet_install_path.generic_string(),
binary_paragraph.spec);
System::print("\n ");
- System::println(Strings::Joiner::on("\n ").join(intersection));
+ System::println(Strings::join("\n ", intersection));
System::println("");
exit(EXIT_FAILURE);
}

MODIFY
src/commands_remove.cpp
src/commands_remove.cpp
@@ -136,9 +136,9 @@ namespace vcpkg::Commands::Remove
{
sort_packages_by_name(&not_installed);
System::println("The following packages are not installed, so not removed:\n%s",
- Strings::Joiner::on("\n ").prefix(" ").join(not_installed, [](const package_spec_with_remove_plan* p)
+ Strings::join("\n ", not_installed, [](const package_spec_with_remove_plan* p)
{
- return p->spec.toString();
+ return " " + p->spec.toString();
}));
}
@@ -146,7 +146,7 @@ namespace vcpkg::Commands::Remove
{
sort_packages_by_name(&remove);
System::println("The following packages will be removed:\n%s",
- Strings::Joiner::on("\n").join(remove, [](const package_spec_with_remove_plan* p)
+ Strings::join("\n", remove, [](const package_spec_with_remove_plan* p)
{
if (p->plan.request_type == Dependencies::request_type::AUTO_SELECTED)
{

MODIFY
src/vcpkg_Strings.cpp
src/vcpkg_Strings.cpp
@@ -78,38 +78,14 @@ namespace vcpkg::Strings
return output;
}
- std::string join(const std::vector<std::string>& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix)
+ std::string join(const std::string& delimiter, const std::vector<std::string>& v)
{
- return join(v, prefix, delimiter, suffix, [](const std::string& i) -> std::string
- {
- return i;
- });
- }
-
- Joiner Joiner::on(const std::string& delimiter)
- {
- return Joiner(delimiter);
- }
-
- Joiner& Joiner::prefix(const std::string& prefix)
- {
- this->m_prefix = prefix;
- return *this;
- }
-
- Joiner& Joiner::suffix(const std::string& suffix)
- {
- this->m_suffix = suffix;
- return *this;
- }
-
- std::string Joiner::join(const std::vector<std::string>& v) const
- {
- return Strings::join(v, this->m_prefix, this->m_delimiter, this->m_suffix);
+ return join(delimiter, v, [](const std::string& p) -> const std::string& { return p; });
}
- Joiner::Joiner(const std::string& delimiter) : m_prefix(""), m_delimiter(delimiter), m_suffix("")
+ 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)

Nuke Joiner. Add wjoin()