-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
acceptedenhancementProposed enhancements of existing featuresProposed enhancements of existing features
Description
Is there an existing issue for this?
- I have searched the existing issues
Description of the Issue
Currently, the functions utilizing the <codecvt> header file are primarily found in two places:
1. In Common.cpp, the functions: s2ws(), ws2s(), and writeLog().
2. In FileInterface.cpp, the functions: Win32_IO_File::Win32_IO_File() and Win32_IO_File::close().
We can achieve this by rewriting s2ws() and ws2s(), and modifying the related code in the other functions to call these updated versions.
Here is the improved implementation of the s2ws() function, which works correctly when compiled with both VS2022 and GCC:
std::wstring s2ws(const std::string& str)
{
if (str.empty()) return std::wstring();
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
if (size_needed <= 0) {
return std::wstring();
}
std::wstring wstr(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wstr[0], size_needed);
wstr.pop_back();
return wstr;
}
And here is the improved implementation of the ws2s() function, which also works correctly with both VS2022 and GCC:
std::string ws2s(const std::wstring& wstr)
{
if (wstr.empty()) return std::string();
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
if (size_needed <= 0) {
return std::string();
}
std::string str(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], size_needed, nullptr, nullptr);
str.pop_back();
return str;
}
Describe the solution you'd like.
none.
Debug Information
Notepad++ v8.7.3 (64-bit)
Build time : Nov 30 2024 - 16:48:13
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.5131
Current ANSI codepage : 1252
Plugins :
mimeTools (3.1)Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedenhancementProposed enhancements of existing featuresProposed enhancements of existing features