Rename Strings:: function for utf8/utf16 conversion
MODIFY
include/vcpkg_Strings.h
include/vcpkg_Strings.h
@@ -48,9 +48,9 @@ namespace vcpkg::Strings
return details::wformat_internal(fmtstr, to_wprintf_arg(to_wprintf_arg(args))...);
}
- std::wstring utf8_to_utf16(const CStringView s);
+ std::wstring to_utf16(const CStringView s);
- std::string utf16_to_utf8(const CWStringView w);
+ std::string to_utf8(const CWStringView w);
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern);

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -297,7 +297,7 @@ namespace vcpkg::PostBuildLint
Checks::check_exit(VCPKG_LINE_INFO,
ec_data.exit_code == 0,
"Running command:\n %s\n failed",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
if (ec_data.output.find("ordinal hint RVA name") == std::string::npos)
{
@@ -334,7 +334,7 @@ namespace vcpkg::PostBuildLint
Checks::check_exit(VCPKG_LINE_INFO,
ec_data.exit_code == 0,
"Running command:\n %s\n failed",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
if (ec_data.output.find("App Container") == std::string::npos)
{
@@ -610,7 +610,7 @@ namespace vcpkg::PostBuildLint
Checks::check_exit(VCPKG_LINE_INFO,
ec_data.exit_code == 0,
"Running command:\n %s\n failed",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
for (const BuildType& bad_build_type : bad_build_types)
{
@@ -664,7 +664,7 @@ namespace vcpkg::PostBuildLint
Checks::check_exit(VCPKG_LINE_INFO,
ec_data.exit_code == 0,
"Running command:\n %s\n failed",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
for (const OutdatedDynamicCrt& outdated_crt : outdated_crts)
{

MODIFY
src/VcpkgCmdArguments.cpp
src/VcpkgCmdArguments.cpp
@@ -48,7 +48,7 @@ namespace vcpkg
std::vector<std::string> v;
for (int i = 1; i < argc; ++i)
{
- v.push_back(Strings::utf16_to_utf8(argv[i]));
+ v.push_back(Strings::to_utf8(argv[i]));
}
return VcpkgCmdArguments::create_from_arg_sequence(v.data(), v.data() + v.size());

MODIFY
src/commands_export.cpp
src/commands_export.cpp
@@ -334,7 +334,7 @@ namespace vcpkg::Commands::Export
"\n"
" %s"
"\n",
- Strings::utf16_to_utf8(cmake_variable.s));
+ Strings::to_utf8(cmake_variable.s));
};
if (raw)

MODIFY
src/commands_hash.cpp
src/commands_hash.cpp
@@ -10,10 +10,8 @@ namespace vcpkg::Commands::Hash
{
auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", path.c_str(), hashType);
auto ec_data = System::cmd_execute_and_capture_output(cmd_line);
- Checks::check_exit(VCPKG_LINE_INFO,
- ec_data.exit_code == 0,
- "Running command:\n %s\n failed",
- Strings::utf16_to_utf8(cmd_line));
+ Checks::check_exit(
+ VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::to_utf8(cmd_line));
std::string const& output = ec_data.output;
@@ -21,13 +19,13 @@ namespace vcpkg::Commands::Hash
Checks::check_exit(VCPKG_LINE_INFO,
start != std::string::npos,
"Unexpected output format from command: %s",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
auto end = output.find_first_of("\r\n", start + 1);
Checks::check_exit(VCPKG_LINE_INFO,
end != std::string::npos,
"Unexpected output format from command: %s",
- Strings::utf16_to_utf8(cmd_line));
+ Strings::to_utf8(cmd_line));
auto hash = output.substr(start, end - start);
Util::erase_remove_if(hash, isspace);
@@ -49,7 +47,7 @@ namespace vcpkg::Commands::Hash
}
if (args.command_arguments.size() == 2)
{
- do_file_hash(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1]));
+ do_file_hash(args.command_arguments[0], Strings::to_utf16(args.command_arguments[1]));
}
Checks::exit_success(VCPKG_LINE_INFO);

MODIFY
src/commands_portsdiff.cpp
src/commands_portsdiff.cpp
@@ -114,7 +114,7 @@ namespace vcpkg::Commands::PortsDiff
Checks::check_exit(VCPKG_LINE_INFO,
output.output == VALID_COMMIT_OUTPUT,
"Invalid commit id %s",
- Strings::utf16_to_utf8(git_commit_id));
+ Strings::to_utf8(git_commit_id));
}
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
@@ -128,9 +128,9 @@ namespace vcpkg::Commands::PortsDiff
const fs::path& git_exe = paths.get_git_exe();
- const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0));
+ const std::wstring git_commit_id_for_previous_snapshot = Strings::to_utf16(args.command_arguments.at(0));
const std::wstring git_commit_id_for_current_snapshot =
- args.command_arguments.size() < 2 ? L"HEAD" : Strings::utf8_to_utf16(args.command_arguments.at(1));
+ args.command_arguments.size() < 2 ? L"HEAD" : Strings::to_utf16(args.command_arguments.at(1));
check_commit_exists(git_exe, git_commit_id_for_current_snapshot);
check_commit_exists(git_exe, git_commit_id_for_previous_snapshot);

MODIFY
src/tests_paragraph.cpp
src/tests_paragraph.cpp
@@ -353,13 +353,13 @@ namespace UnitTest1
TEST_METHOD(utf8_to_utf16)
{
- auto str = vcpkg::Strings::utf8_to_utf16("abc");
+ auto str = vcpkg::Strings::to_utf16("abc");
Assert::AreEqual(L"abc", str.c_str());
}
TEST_METHOD(utf8_to_utf16_with_whitespace)
{
- auto str = vcpkg::Strings::utf8_to_utf16("abc -x86-windows");
+ auto str = vcpkg::Strings::to_utf16("abc -x86-windows");
Assert::AreEqual(L"abc -x86-windows", str.c_str());
}
};

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
@@ -41,7 +41,7 @@ static void inner(const VcpkgCmdArguments& args)
fs::path vcpkg_root_dir;
if (args.vcpkg_root_dir != nullptr)
{
- vcpkg_root_dir = fs::stdfs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir));
+ vcpkg_root_dir = fs::stdfs::absolute(Strings::to_utf16(*args.vcpkg_root_dir));
}
else
{
@@ -85,7 +85,7 @@ static void inner(const VcpkgCmdArguments& args)
System::get_environmental_variable(L"VCPKG_DEFAULT_TRIPLET");
if (auto v = vcpkg_default_triplet_env.get())
{
- default_triplet = Triplet::from_canonical_name(Strings::utf16_to_utf8(*v));
+ default_triplet = Triplet::from_canonical_name(Strings::to_utf8(*v));
}
else
{
@@ -200,7 +200,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
Metrics::track_property("version", Commands::Version::version());
- const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW()));
+ const std::string trimmed_command_line = trim_path_from_command_line(Strings::to_utf8(GetCommandLineW()));
Metrics::track_property("cmdline", trimmed_command_line);
loadConfig();
Metrics::track_property("sqmuser", Metrics::get_SQM_user());
@@ -247,6 +247,6 @@ int wmain(const int argc, const wchar_t* const* const argv)
exc_msg);
fflush(stdout);
for (int x = 0; x < argc; ++x)
- System::println("%s|", Strings::utf16_to_utf8(argv[x]));
+ System::println("%s|", Strings::to_utf8(argv[x]));
fflush(stdout);
}

MODIFY
src/vcpkg_Build.cpp
src/vcpkg_Build.cpp
@@ -35,7 +35,7 @@ namespace vcpkg::Build
}
return Strings::wformat(
- LR"("%s" %s %s 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(triplet.architecture()), tonull);
+ LR"("%s" %s %s 2>&1)", toolset.vcvarsall.native(), Strings::to_utf16(triplet.architecture()), tonull);
}
static void create_binary_control_file(const VcpkgPaths& paths,

MODIFY
src/vcpkg_Strings.cpp
src/vcpkg_Strings.cpp
@@ -46,13 +46,13 @@ namespace vcpkg::Strings::details
namespace vcpkg::Strings
{
- std::wstring utf8_to_utf16(const CStringView s)
+ std::wstring to_utf16(const CStringView s)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
return conversion.from_bytes(s);
}
- std::string utf16_to_utf8(const CWStringView w)
+ std::string to_utf8(const CWStringView w)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
return conversion.to_bytes(w);

MODIFY
src/vcpkg_System.cpp
src/vcpkg_System.cpp
@@ -97,7 +97,7 @@ namespace vcpkg::System
// Basically we are wrapping it in quotes
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
- if (g_debugging) System::println("[DEBUG] _wspawnlpe(cmd.exe /c %s)", Strings::utf16_to_utf8(actual_cmd_line));
+ if (g_debugging) System::println("[DEBUG] _wspawnlpe(cmd.exe /c %s)", Strings::to_utf8(actual_cmd_line));
auto exit_code =
_wspawnlpe(_P_WAIT, L"cmd.exe", L"cmd.exe", L"/c", actual_cmd_line.c_str(), nullptr, env_cstr.data());
if (g_debugging) System::println("[DEBUG] _wspawnlpe() returned %d", exit_code);
@@ -111,7 +111,7 @@ namespace vcpkg::System
// Basically we are wrapping it in quotes
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
- if (g_debugging) System::println("[DEBUG] _wsystem(%s)", Strings::utf16_to_utf8(actual_cmd_line));
+ if (g_debugging) System::println("[DEBUG] _wsystem(%s)", Strings::to_utf8(actual_cmd_line));
int exit_code = _wsystem(actual_cmd_line.c_str());
if (g_debugging) System::println("[DEBUG] _wsystem() returned %d", exit_code);
return exit_code;

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
@@ -219,7 +219,7 @@ namespace vcpkg
{
}
CMakeVariable::CMakeVariable(const CWStringView varname, const std::string& varvalue)
- : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str())
+ : CMakeVariable(varname, Strings::to_utf16(varvalue).c_str())
{
}
CMakeVariable::CMakeVariable(const CWStringView varname, const std::wstring& varvalue)

Rename Strings:: function for utf8/utf16 conversion