WideToUTF8 Utility

RTA does a lot of string conversions!
This commit is contained in:
HikikoMarmy
2025-04-24 11:18:08 +01:00
parent 8b03d059bb
commit a1989de8dc
2 changed files with 21 additions and 0 deletions

View File

@@ -42,3 +42,22 @@ uint32_t Utility::swap_endian( uint32_t val )
( ( val >> 8 ) & 0x0000FF00 ) |
( ( val >> 24 ) & 0x000000FF );
}
std::string Utility::WideToUTF8( const std::wstring &wstr )
{
if( wstr.empty() ) return {};
int size_needed = WideCharToMultiByte(
CP_UTF8, 0, wstr.c_str(), static_cast< int >( wstr.size() ),
nullptr, 0, nullptr, nullptr
);
std::string result( size_needed, 0 );
WideCharToMultiByte(
CP_UTF8, 0, wstr.c_str(), static_cast< int >( wstr.size() ),
&result[ 0 ], size_needed, nullptr, nullptr
);
return result;
}

View File

@@ -7,4 +7,6 @@ namespace Utility
uint16_t swap_endian( uint16_t val );
uint32_t swap_endian( uint32_t val );
std::string WideToUTF8( const std::wstring &wstr );
}