diff --git a/src/node_file.cc b/src/node_file.cc index f77cc88fcb4246..7eb2aefa0babea 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3137,7 +3137,7 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { THROW_IF_INSUFFICIENT_PERMISSIONS( env, permission::PermissionScope::kFileSystemRead, src.ToStringView()); - auto src_path = BufferValueToPath(src); + auto src_path = StringViewToPath(src.ToStringView()); BufferValue dest(isolate, args[1]); CHECK_NOT_NULL(*dest); @@ -3145,7 +3145,7 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { THROW_IF_INSUFFICIENT_PERMISSIONS( env, permission::PermissionScope::kFileSystemWrite, dest.ToStringView()); - auto dest_path = BufferValueToPath(dest); + auto dest_path = StringViewToPath(dest.ToStringView()); bool dereference = args[2]->IsTrue(); bool recursive = args[3]->IsTrue(); diff --git a/src/node_modules.cc b/src/node_modules.cc index f539002a51bd08..4a3e7f59eb7efe 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -337,7 +337,7 @@ void BindingData::GetNearestParentPackageJSON( bool slashCheck = path_value.ToStringView().ends_with(kPathSeparator); ToNamespacedPath(realm->env(), &path_value); - std::filesystem::path path = BufferValueToPath(path_value); + std::filesystem::path path = StringViewToPath(path_value.ToStringView()); if (slashCheck) { path += kPathSeparator; } @@ -361,7 +361,7 @@ void BindingData::GetNearestParentPackageJSONType( bool slashCheck = path_value.ToStringView().ends_with(kPathSeparator); ToNamespacedPath(realm->env(), &path_value); - std::filesystem::path path = BufferValueToPath(path_value); + std::filesystem::path path = StringViewToPath(path_value.ToStringView()); if (slashCheck) { path += kPathSeparator; } diff --git a/src/util.cc b/src/util.cc index 531a5330c2cb74..a3365fb73a8f1f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -352,8 +352,8 @@ void DiagnosticFilename::LocalTime(TIME_TYPE* tm_struct) { // Defined in node_internals.h std::string DiagnosticFilename::MakeFilename( uint64_t thread_id, - const char* prefix, - const char* ext) { + const char* prefix, + const char* ext) { std::ostringstream oss; TIME_TYPE tm_struct; LocalTime(&tm_struct); @@ -886,14 +886,14 @@ v8::Maybe GetValidFileMode(Environment* env, } #ifdef _WIN32 -std::wstring ConvertToWideString(const std::string& str) { +std::wstring ConvertToWideString(std::string_view strView) { int size_needed = MultiByteToWideChar( - CP_UTF8, 0, &str[0], static_cast(str.size()), nullptr, 0); + CP_UTF8, 0, strView.data(), static_cast(strView.size()), nullptr, 0); std::wstring wstrTo(size_needed, 0); MultiByteToWideChar(CP_UTF8, 0, - &str[0], - static_cast(str.size()), + strView.data(), + static_cast(strView.size()), &wstrTo[0], size_needed); return wstrTo; @@ -921,7 +921,6 @@ std::string ConvertWideToUTF8(const std::wstring& wstr) { nullptr); return strTo; } - #endif // _WIN32 } // namespace node diff --git a/src/util.h b/src/util.h index d32c71cd70aee8..0ac988f69a0814 100644 --- a/src/util.h +++ b/src/util.h @@ -1019,19 +1019,27 @@ v8::Maybe GetValidFileMode(Environment* env, inline bool IsWindowsBatchFile(const char* filename); #ifdef _WIN32 -std::wstring ConvertToWideString(const std::string& str); +std::wstring ConvertToWideString(const std::string_view str); -#define BufferValueToPath(str) \ - std::filesystem::path(ConvertToWideString(str.ToString())) +inline std::filesystem::path StringViewToPath( + std::string_view str) { + return std::filesystem::path(ConvertToWideString(str)); +} std::string ConvertWideToUTF8(const std::wstring& wstr); -#define PathToString(path) ConvertWideToUTF8(path.wstring()); +inline std::string PathToString(std::filesystem::path path) { + return ConvertWideToUTF8(path.wstring()); +} #else // _WIN32 -#define BufferValueToPath(str) std::filesystem::path(str.ToStringView()); -#define PathToString(path) path.native(); +inline std::filesystem::path StringViewToPath(std::string_view str) { + return std::filesystem::path(str); +} +inline std::string PathToString(std::filesystem::path path) { + return path.native(); +} #endif // _WIN32