[vcpkg] Remove utf16 usage from non-Windows

This commit is contained in:
Robert Schumacher 2018-05-03 15:03:35 -07:00
parent 6ec3a48633
commit 8f0ebdf8d5
4 changed files with 13 additions and 12 deletions

View File

@ -34,9 +34,11 @@ namespace vcpkg::Strings
return details::format_internal(fmtstr, to_printf_arg(to_printf_arg(args))...);
}
#if defined(_WIN32)
std::wstring to_utf16(const CStringView& s);
std::string to_utf8(const wchar_t* w);
#endif
std::string escape_string(const CStringView& s, char char_to_escape, char escape_char);

View File

@ -70,7 +70,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::to_utf16(*args.vcpkg_root_dir));
vcpkg_root_dir = fs::stdfs::absolute(fs::u8path(*args.vcpkg_root_dir));
}
else
{
@ -94,6 +94,8 @@ static void inner(const VcpkgCmdArguments& args)
Checks::check_exit(VCPKG_LINE_INFO, !vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root.");
Debug::println("Using vcpkg-root: %s", vcpkg_root_dir.u8string());
auto default_vs_path = System::get_environment_variable("VCPKG_DEFAULT_VS_PATH").value_or("");
const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir, default_vs_path);

View File

@ -56,16 +56,17 @@ namespace vcpkg::Files
const std::string& filename) const override
{
fs::path current_dir = starting_dir;
for (; !current_dir.empty(); current_dir = current_dir.parent_path())
fs::path unix_root = "/";
for (; !current_dir.empty() && current_dir != unix_root; current_dir = current_dir.parent_path())
{
const fs::path candidate = current_dir / filename;
if (exists(candidate))
{
break;
return current_dir;
}
}
return current_dir;
return fs::path();
}
virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const override

View File

@ -49,33 +49,29 @@ namespace vcpkg::Strings::details
namespace vcpkg::Strings
{
#if defined(_WIN32)
std::wstring to_utf16(const CStringView& s)
{
#if defined(_WIN32)
std::wstring output;
const size_t size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
if (size == 0) return output;
output.resize(size - 1);
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), static_cast<int>(size) - 1);
return output;
#else
Checks::unreachable(VCPKG_LINE_INFO);
#endif
}
#endif
#if defined(_WIN32)
std::string to_utf8(const wchar_t* w)
{
#if defined(_WIN32)
std::string output;
const size_t size = WideCharToMultiByte(CP_UTF8, 0, w, -1, nullptr, 0, nullptr, nullptr);
if (size == 0) return output;
output.resize(size - 1);
WideCharToMultiByte(CP_UTF8, 0, w, -1, output.data(), static_cast<int>(size) - 1, nullptr, nullptr);
return output;
#else
Checks::unreachable(VCPKG_LINE_INFO);
#endif
}
#endif
std::string escape_string(const CStringView& s, char char_to_escape, char escape_char)
{