Use CSlice in to_wstring.

GitOrigin-RevId: 53f77206fbc34cd68036f994a7ee90fda2b1b636
This commit is contained in:
levlam 2018-05-18 17:22:18 +03:00
parent 536508193a
commit 18818fd4ff
3 changed files with 4 additions and 3 deletions

View File

@ -212,11 +212,12 @@ Status walk_path_dir(const std::wstring &dir_name, Func &&func) {
template <class Func> template <class Func>
Status walk_path(CSlice path, Func &&func) { Status walk_path(CSlice path, Func &&func) {
TRY_RESULT(wpath, to_wstring(path));
Slice path_slice = path; Slice path_slice = path;
while (!path_slice.empty() && (path_slice.back() == '/' || path_slice.back() == '\\')) { while (!path_slice.empty() && (path_slice.back() == '/' || path_slice.back() == '\\')) {
path_slice.remove_suffix(1); path_slice.remove_suffix(1);
wpath.pop_back();
} }
TRY_RESULT(wpath, to_wstring(path_slice));
return detail::walk_path_dir(wpath.c_str(), func); return detail::walk_path_dir(wpath.c_str(), func);
} }

View File

@ -31,7 +31,7 @@ class UsableFacet : public Facet {
}; };
} // namespace detail } // namespace detail
Result<std::wstring> to_wstring(Slice slice) { Result<std::wstring> to_wstring(CSlice slice) {
// TODO(perf): optimize // TODO(perf): optimize
std::wstring_convert<detail::UsableFacet<std::codecvt_utf8_utf16<wchar_t>>> converter; std::wstring_convert<detail::UsableFacet<std::codecvt_utf8_utf16<wchar_t>>> converter;
auto res = converter.from_bytes(slice.begin(), slice.end()); auto res = converter.from_bytes(slice.begin(), slice.end());

View File

@ -18,7 +18,7 @@
namespace td { namespace td {
Result<std::wstring> to_wstring(Slice slice); Result<std::wstring> to_wstring(CSlice slice);
Result<string> from_wstring(const std::wstring &str); Result<string> from_wstring(const std::wstring &str);