From 18818fd4ff14cd697d8c0ec880d9fab2d6ec494b Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 18 May 2018 17:22:18 +0300 Subject: [PATCH] Use CSlice in to_wstring. GitOrigin-RevId: 53f77206fbc34cd68036f994a7ee90fda2b1b636 --- tdutils/td/utils/port/path.h | 3 ++- tdutils/td/utils/port/wstring_convert.cpp | 2 +- tdutils/td/utils/port/wstring_convert.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tdutils/td/utils/port/path.h b/tdutils/td/utils/port/path.h index 47b7d3a3..727ee173 100644 --- a/tdutils/td/utils/port/path.h +++ b/tdutils/td/utils/port/path.h @@ -212,11 +212,12 @@ Status walk_path_dir(const std::wstring &dir_name, Func &&func) { template Status walk_path(CSlice path, Func &&func) { + TRY_RESULT(wpath, to_wstring(path)); Slice path_slice = path; while (!path_slice.empty() && (path_slice.back() == '/' || path_slice.back() == '\\')) { path_slice.remove_suffix(1); + wpath.pop_back(); } - TRY_RESULT(wpath, to_wstring(path_slice)); return detail::walk_path_dir(wpath.c_str(), func); } diff --git a/tdutils/td/utils/port/wstring_convert.cpp b/tdutils/td/utils/port/wstring_convert.cpp index 56da62b9..8dd83cc7 100644 --- a/tdutils/td/utils/port/wstring_convert.cpp +++ b/tdutils/td/utils/port/wstring_convert.cpp @@ -31,7 +31,7 @@ class UsableFacet : public Facet { }; } // namespace detail -Result to_wstring(Slice slice) { +Result to_wstring(CSlice slice) { // TODO(perf): optimize std::wstring_convert>> converter; auto res = converter.from_bytes(slice.begin(), slice.end()); diff --git a/tdutils/td/utils/port/wstring_convert.h b/tdutils/td/utils/port/wstring_convert.h index a795d2bd..5d6ed69d 100644 --- a/tdutils/td/utils/port/wstring_convert.h +++ b/tdutils/td/utils/port/wstring_convert.h @@ -18,7 +18,7 @@ namespace td { -Result to_wstring(Slice slice); +Result to_wstring(CSlice slice); Result from_wstring(const std::wstring &str);