mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Platform: Improve Windows wstring support
This commit is contained in:
committed by
Kyle Schwarz
parent
c5ba2d8d32
commit
f04cd16bee
@@ -0,0 +1,26 @@
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
|
||||
#include <icsneo/platform/windows/strings.h>
|
||||
|
||||
// Helper function to convert UTF-16 to UTF-8 strings (wide to standard)
|
||||
std::string icsneo::convertWideString(const std::wstring& value) {
|
||||
// Get the width of the string (character count)
|
||||
int width = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)value.c_str(), -1, 0, 0, NULL, NULL);
|
||||
// Create the new string
|
||||
std::string new_string(width+1, '\0');
|
||||
// fill the new string with the converted characters
|
||||
WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)value.c_str(), -1, new_string.data(), width, NULL, NULL);
|
||||
return new_string;
|
||||
};
|
||||
|
||||
// Helper function to convert UTF-8 to UTF-16 strings (standard to wide)
|
||||
std::wstring icsneo::convertStringToWide(const std::string& value) {
|
||||
// Get the width of the string (character count)
|
||||
int width = MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, NULL, 0);
|
||||
// Create the new string
|
||||
std::wstring new_string(width+1, '\0');
|
||||
// fill the new string with the converted characters
|
||||
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, (LPWSTR)new_string.data(), width);
|
||||
return new_string;
|
||||
}
|
||||
Reference in New Issue
Block a user