mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
rwcore: convert windows wide string to ACP (active code page)
This commit is contained in:
parent
c0f11c2935
commit
22437f9f25
@ -44,6 +44,14 @@ add_library(rwcore
|
||||
loaders/LoaderTXD.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(rwcore
|
||||
PRIVATE
|
||||
platform/RWWindows.hpp
|
||||
platform/RWWindows.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(rwcore
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
|
30
rwcore/platform/RWWindows.cpp
Normal file
30
rwcore/platform/RWWindows.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "RWWindows.hpp"
|
||||
|
||||
#include "rw/Debug.hpp"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
std::string wideStringToACP(const wchar_t* wString) {
|
||||
std::string returnValue;
|
||||
bool result = true;
|
||||
|
||||
int nbChars = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wString, -1,
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
if (nbChars == 0) {
|
||||
if (GetLastError() != ERROR_SUCCESS) {
|
||||
RW_ERROR("Unable to calculate length of wide string");
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
returnValue.resize(nbChars);
|
||||
nbChars =
|
||||
WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wString, -1,
|
||||
&returnValue.front(), nbChars, nullptr, nullptr);
|
||||
if (nbChars == 0) {
|
||||
returnValue.resize(0);
|
||||
return returnValue;
|
||||
}
|
||||
returnValue.resize(nbChars - 1);
|
||||
return returnValue;
|
||||
}
|
14
rwcore/platform/RWWindows.hpp
Normal file
14
rwcore/platform/RWWindows.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _RWCORE_PLATFORM_RWWINDOWS_HPP_
|
||||
#define _RWCORE_PLATFORM_RWWINDOWS_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief Convert a wide string to a ACP string (=active code page)
|
||||
* This function converts to the active code page instead of utf8
|
||||
* because Windows functions need to understand the encoding.
|
||||
* @param str The wide string to convert
|
||||
*/
|
||||
std::string wideStringToACP(const wchar_t* str);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user