Skip to content

Commit

Permalink
[vcpkg] Remove utf16 usage from non-Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed May 3, 2018
1 parent 6ec3a48 commit 8f0ebdf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions toolsrc/include/vcpkg/base/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions toolsrc/src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions toolsrc/src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 8f0ebdf

Please sign in to comment.