5#include "Stroika/Foundation/Containers/Common.h"
8 [[noreturn]]
void ThrowSystemErrNo ();
9 [[noreturn]]
void ThrowSystemErrNo (
int sysErr);
21#if qTargetPlatformSDKUseswchar_t
22#if qStroika_Foundation_Common_Platform_Windows
23 static constexpr DWORD kFLAGS_ = MB_ERR_INVALID_CHARS;
24 int stringLength = ::MultiByteToWideChar (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
nullptr, 0);
25 if (stringLength == 0 and s.size () != 0) {
26 Execution::ThrowSystemErrNo ();
29 result.resize (stringLength);
30 Verify (::MultiByteToWideChar (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
Containers::Start (result), stringLength) == stringLength);
41#if qTargetPlatformSDKUseswchar_t
49#if qTargetPlatformSDKUseswchar_t
50#if qStroika_Foundation_Common_Platform_Windows
51 static constexpr DWORD kFLAGS_ = 0;
52 int stringLength = ::MultiByteToWideChar (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
nullptr, 0);
53 if (stringLength == 0 and s.size () != 0) {
54 Execution::ThrowSystemErrNo ();
57 result.resize (stringLength);
58 Verify (::MultiByteToWideChar (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
Containers::Start (result), stringLength) == stringLength);
69#if qTargetPlatformSDKUseswchar_t
107#if qTargetPlatformSDKUseswchar_t
108#if qStroika_Foundation_Common_Platform_Windows
109 static constexpr DWORD kFLAGS_ = 0;
110 int stringLength = ::WideCharToMultiByte (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
nullptr, 0,
nullptr,
nullptr);
111 if (stringLength == 0 and s.size () != 0) {
112 Execution::ThrowSystemErrNo ();
115 result.resize (stringLength);
116 BOOL usedDefaultChar{
false};
117 Verify (::WideCharToMultiByte (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
Containers::Start (result), stringLength,
118 nullptr, &usedDefaultChar) == stringLength);
119 if (usedDefaultChar) {
120 Execution::ThrowSystemErrNo (ERROR_NO_UNICODE_TRANSLATION);
127 return string{s.begin (), s.end ()};
132#if qTargetPlatformSDKUseswchar_t
140#if qTargetPlatformSDKUseswchar_t
141#if qStroika_Foundation_Common_Platform_Windows
142 static constexpr DWORD kFLAGS_ = 0;
143 int stringLength = ::WideCharToMultiByte (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
nullptr, 0,
nullptr,
nullptr);
144 if (stringLength == 0 and s.size () != 0) {
145 Execution::ThrowSystemErrNo ();
148 result.resize (stringLength);
149 Verify (::WideCharToMultiByte (CP_ACP, kFLAGS_, s.data (),
static_cast<int> (s.size ()),
Containers::Start (result), stringLength,
150 nullptr,
nullptr) == stringLength);
156 return string{s.begin (), s.end ()};
161#if qTargetPlatformSDKUseswchar_t
173#if qTargetPlatformSDKUseswchar_t
174 inline wstring
SDK2Wide (span<const SDKChar> s)
176 return wstring{s.begin (), s.end ()};
181#if qTargetPlatformSDKUseswchar_t
187#if qTargetPlatformSDKUseswchar_t
190 return wstring{s.begin (), s.end ()};
195#if qTargetPlatformSDKUseswchar_t
207#if qTargetPlatformSDKUseswchar_t
215#if qTargetPlatformSDKUseswchar_t
221#if qTargetPlatformSDKUseswchar_t
229#if qTargetPlatformSDKUseswchar_t
241 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
243 "Since Stroika v3.0d1 use String::FromNarrowSDKString (s).As<wstring> () - less efficent but this is never used")]]
inline wstring
244 NarrowSDKStringToWide (
const string& s)
247 Assert (CP_ACP == 0);
249 const unsigned char CP_ACP = 0;
251 return NarrowStringToWide (s, CP_ACP);
253 [[deprecated (
"Since Stroika v3.0d1 use String (s).AsNarrowSDKString () - less efficent but this is never used")]]
inline string
254 WideStringToNarrowSDKString (
const wstring& ws)
257 Assert (CP_ACP == 0);
259 const unsigned char CP_ACP = 0;
261 return WideStringToNarrow (ws, CP_ACP);
264 "Since Stroika v3.0d1 use String::FromSDKString (s).AsNarrowSDKString () - less efficent but this is never used")]]
inline string
267#if qTargetPlatformSDKUseswchar_t
268 return WideStringToNarrowSDKString (s);
274 "Since Stroika v3.0d1 use String::FromNarrowSDKString (s).AsSDKString () - less efficent but this is never used")]]
inline SDKString
275 NarrowSDK2SDKString (
const string& s)
277#if qTargetPlatformSDKUseswchar_t
278 return NarrowSDKStringToWide (s);
283 [[deprecated (
"Since Stroika v3.0d1 use String{s}.AsSDKString () - less efficent but this is never used")]]
inline SDKString
284 Wide2SDKString (
const wstring& s)
286#if qTargetPlatformSDKUseswchar_t
289 return WideStringToNarrowSDKString (s);
292 [[deprecated (
"Since Stroika v3.0d1 - just use String::FromNarrowSDKString (s).AsSDKString ()")]]
inline SDKString ToSDKString (
const string& s)
294 return NarrowSDK2SDKString (s);
296 [[deprecated (
"Since Stroika v3.0d1 - just use String(s).AsSDKString ()")]]
inline SDKString ToSDKString (
const wstring& s)
298 return Wide2SDKString (s);
300 DISABLE_COMPILER_MSC_WARNING_END (4996);
301 DISABLE_COMPILER_GCC_WARNING_END (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
#define AssertNotImplemented()
wstring NarrowSDK2Wide(span< const char > s)
SDKString Wide2SDK(span< const wchar_t > s)
wstring SDK2Wide(span< const SDKChar > s)
basic_string< SDKChar > SDKString
SDKString Narrow2SDK(span< const char > s)
DISABLE_COMPILER_MSC_WARNING_START(4996)
AllowMissingCharacterErrorsFlag
string SDK2Narrow(span< const SDKChar > s)
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...