9#if qStroika_Foundation_Common_Platform_Windows
10#include "Stroika/Foundation/Characters/Platform/Windows/CodePage.h"
22 inline CodePage CodePageNotSupportedException::GetCodePage ()
const
32 inline vector<CodePage> CodePagesInstalled::GetAll ()
36 inline bool CodePagesInstalled::IsCodePageAvailable (
CodePage cp)
38 return find (fCodePages_.begin (), fCodePages_.end (), cp) == fCodePages_.end ();
45 class [[deprecated (
"Since Stroika v3.0d2, use ReadByteOrderMark")]] CodePagesGuesser {
47 enum class Confidence : uint8_t {
64 nonvirtual
CodePage Guess (
const void* input,
size_t nBytes, Confidence* confidence =
nullptr,
size_t* bytesFromFrontToStrip =
nullptr);
71 kCodePage_INVALID [[deprecated (
"Since v3.0d2 - deprecated - use optional")]] = 0xffffffff,
73 kCodePage_ANSI [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kANSI")]] = WellKnownCodePages::kANSI,
75 kCodePage_MAC [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kMAC")]] = WellKnownCodePages::kMAC,
76 kCodePage_PC [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kPC")]] = WellKnownCodePages::kPC,
77 kCodePage_PCA [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kPCA")]] = WellKnownCodePages::kPCA,
78 kCodePage_Thai [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kThai")]] = WellKnownCodePages::kThai,
79 kCodePage_SJIS [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kSJIS")]] = WellKnownCodePages::kSJIS,
80 kCodePage_GB2312 [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kGB2312")]] = WellKnownCodePages::kGB2312,
81 kCodePage_Korean [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kKorean")]] = WellKnownCodePages::kKorean,
82 kCodePage_BIG5 [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kBIG5")]] = WellKnownCodePages::kBIG5,
83 kCodePage_EasternEuropean [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kEasternEuropean")]] =
84 WellKnownCodePages::kEasternEuropean,
85 kCodePage_CYRILIC [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kCyrilic")]] = WellKnownCodePages::kCyrilic,
86 kCodePage_GREEK [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kGreek")]] = WellKnownCodePages::kGreek,
87 kCodePage_Turkish [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kTurkish")]] = WellKnownCodePages::kTurkish,
88 kCodePage_HEBREW [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kHebrew")]] = WellKnownCodePages::kHebrew,
89 kCodePage_ARABIC [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kArabic")]] = WellKnownCodePages::kArabic,
90 kCodePage_Baltic [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kBaltic")]] = WellKnownCodePages::kBaltic,
91 kCodePage_Vietnamese [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kVietnamese")]] = WellKnownCodePages::kVietnamese,
93 kCodePage_UNICODE_WIDE [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kUNICODE_WIDE")]] = WellKnownCodePages::kUNICODE_WIDE,
94 kCodePage_UNICODE_WIDE_BIGENDIAN [[deprecated (
"Since v3.0d2 - deprecated - use WellKnownCodePages::kUNICODE_WIDE_BIGENDIAN")]] =
95 WellKnownCodePages::kUNICODE_WIDE_BIGENDIAN,
97 kCodePage_UTF7 [[deprecated (
"Since v3.0d2 - UTF-7 deprecated")]] = 65000,
98 kCodePage_UTF8 [[deprecated (
"Since v3.0d2 - WellKnownCodePages::kUTF8")]] = WellKnownCodePages::kUTF8
101 class [[deprecated (
"Since Stroika v3.0d2, use CodeCvt - for example - CodeCvt<wchar_t>{locale{}}.String2Bytes<SDKString> (span<const "
102 "wchar_t>{s})")]] CodePageConverter {
104 enum class HandleBOMFlag {
107 static constexpr HandleBOMFlag eHandleBOM = HandleBOMFlag::eHandleBOM;
112 CodePageConverter (CodePage codePage);
113 CodePageConverter (CodePage codePage, HandleBOMFlag h);
136 nonvirtual
bool GetHandleBOM ()
const;
140 nonvirtual
void SetHandleBOM (
bool handleBOM);
154 nonvirtual
void MapToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
char16_t* outChars,
size_t* outCharCnt)
const;
155 nonvirtual
void MapToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
char32_t* outChars,
size_t* outCharCnt)
const;
156 nonvirtual
void MapToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
wchar_t* outChars,
size_t* outCharCnt)
const;
163 nonvirtual
size_t MapToUNICODE_QuickComputeOutBufSize (
const char* inMBChars,
size_t inMBCharCnt)
const;
165 nonvirtual
void MapFromUNICODE (
const char16_t* inChars,
size_t inCharCnt,
char* outChars,
size_t* outCharCnt)
const;
166 nonvirtual
void MapFromUNICODE (
const char32_t* inChars,
size_t inCharCnt,
char* outChars,
size_t* outCharCnt)
const;
167 nonvirtual
void MapFromUNICODE (
const wchar_t* inChars,
size_t inCharCnt,
char* outChars,
size_t* outCharCnt)
const;
173 nonvirtual
size_t MapFromUNICODE_QuickComputeOutBufSize (
const char16_t* inChars,
size_t inCharCnt)
const;
174 nonvirtual
size_t MapFromUNICODE_QuickComputeOutBufSize (
const char32_t* inChars,
size_t inCharCnt)
const;
175 nonvirtual
size_t MapFromUNICODE_QuickComputeOutBufSize (
const wchar_t* inChars,
size_t inCharCnt)
const;
181 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt")]]
inline void MapSBUnicodeTextWithMaybeBOMToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
182 wchar_t* outChars,
size_t* outCharCnt)
185 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
186 DISABLE_COMPILER_CLANG_WARNING_START (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
189 [[maybe_unused]]
size_t outBufSize = *outCharCnt;
190 CodePagesGuesser::Confidence confidence = CodePagesGuesser::Confidence::eLow;
191 CodePage cp = CodePagesGuesser{}.Guess (inMBChars, inMBCharCnt, &confidence,
nullptr);
192 if (confidence <= CodePagesGuesser::Confidence::eLow) {
193 cp = WellKnownCodePages::kUTF8;
195 CodePageConverter cpCvt (cp, CodePageConverter::eHandleBOM);
196 cpCvt.MapToUNICODE (inMBChars, inMBCharCnt, outChars, outCharCnt);
197 Ensure (*outCharCnt <= outBufSize);
198 DISABLE_COMPILER_MSC_WARNING_END (4996);
199 DISABLE_COMPILER_GCC_WARNING_END (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
200 DISABLE_COMPILER_CLANG_WARNING_END (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
208 [[deprecated (
"Since Stroika v3.0d2 - on windows use CP_ACP, and elsewhere probably dont use")]]
inline CodePage GetDefaultSDKCodePage ()
210#if qStroika_Foundation_Common_Platform_Windows
213 Assert (CP_ACP == 0);
221 return WellKnownCodePages::kUTF8;
230 inline CodePageConverter::CodePageConverter (
CodePage codePage)
232 , fCodePage{codePage}
235 inline CodePageConverter::CodePageConverter (CodePage codePage, [[maybe_unused]] HandleBOMFlag h)
237 , fCodePage{codePage}
239 Require (h == eHandleBOM);
241 inline bool CodePageConverter::GetHandleBOM ()
const
245 inline void CodePageConverter::SetHandleBOM (
bool handleBOM)
247 fHandleBOM = handleBOM;
249 inline size_t CodePageConverter::MapToUNICODE_QuickComputeOutBufSize (
const char* ,
size_t inMBCharCnt)
const
251 size_t resultSize = inMBCharCnt;
254 inline void CodePageConverter::MapToUNICODE (
const char* inMBChars,
size_t inMBCharCnt,
wchar_t* outChars,
size_t* outCharCnt)
const
256 static_assert ((
sizeof (wchar_t) ==
sizeof (
char16_t)) or (
sizeof (
wchar_t) ==
sizeof (char32_t)),
257 "(sizeof (wchar_t) == sizeof (char16_t)) or (sizeof (wchar_t) == sizeof (char32_t))");
258 if constexpr (
sizeof (wchar_t) ==
sizeof (
char16_t)) {
259 MapToUNICODE (inMBChars, inMBCharCnt,
reinterpret_cast<char16_t*
> (outChars), outCharCnt);
261 else if constexpr (
sizeof (wchar_t) ==
sizeof (
char32_t)) {
262 MapToUNICODE (inMBChars, inMBCharCnt,
reinterpret_cast<char32_t*
> (outChars), outCharCnt);
265 inline void CodePageConverter::MapFromUNICODE (
const wchar_t* inChars,
size_t inCharCnt,
char* outChars,
size_t* outCharCnt)
const
267 static_assert ((
sizeof (wchar_t) ==
sizeof (
char16_t)) or (
sizeof (
wchar_t) ==
sizeof (char32_t)),
268 "(sizeof (wchar_t) == sizeof (char16_t)) or (sizeof (wchar_t) == sizeof (char32_t))");
269 if constexpr (
sizeof (wchar_t) ==
sizeof (
char16_t)) {
270 MapFromUNICODE (
reinterpret_cast<const char16_t*
> (inChars), inCharCnt, outChars, outCharCnt);
272 else if constexpr (
sizeof (wchar_t) ==
sizeof (
char32_t)) {
273 MapFromUNICODE (
reinterpret_cast<const char32_t*
> (inChars), inCharCnt, outChars, outCharCnt);
277 DISABLE_COMPILER_MSC_WARNING_START (4996);
278 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
279 DISABLE_COMPILER_CLANG_WARNING_START (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
283 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
void NarrowStringToWide (
const char* sStart,
const char* sEnd,
284 CodePage codePage, wstring* intoResult);
285 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
inline void NarrowStringToWide (
const string& s,
CodePage codePage, wstring* intoResult)
288 const char* sp = s.c_str ();
289 NarrowStringToWide (sp, sp + s.length (), codePage, intoResult);
291 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
inline wstring NarrowStringToWide (
const string& s, CodePage codePage)
294 NarrowStringToWide (s, codePage, &result);
297 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String::FromUTF8")]]
inline void UTF8StringToWide (
const char* s, wstring* intoStr)
300 NarrowStringToWide (s, s + ::strlen (s), WellKnownCodePages::kUTF8, intoStr);
302 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
inline void UTF8StringToWide (
const string& s, wstring* intoStr)
304 NarrowStringToWide (s, WellKnownCodePages::kUTF8, intoStr);
306 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
inline wstring UTF8StringToWide (
const char* s)
310 NarrowStringToWide (s, s + ::strlen (s), WellKnownCodePages::kUTF8, &result);
313 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt or String")]]
inline wstring UTF8StringToWide (
const string& s)
315 return NarrowStringToWide (s, WellKnownCodePages::kUTF8);
318 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt")]]
void WideStringToNarrow (
const wchar_t* wsStart,
const wchar_t* wsEnd,
319 CodePage codePage,
string* intoResult);
321 [[deprecated (
"Since Stroika v3.0d2 - ")]]
inline void WideStringToNarrow (
const wstring& ws, CodePage codePage,
string* intoResult)
324 const wchar_t* wsp = ws.c_str ();
325 WideStringToNarrow (wsp, wsp + ws.length (), codePage, intoResult);
327 [[deprecated (
"Since Stroika v3.0d2 - ")]]
inline string WideStringToNarrow (
const wstring& ws, CodePage codePage)
330 WideStringToNarrow (ws, codePage, &result);
336 [[deprecated (
"Since Stroika v3.0d2 - use String::FromSDKString ().AsUTF8 () or CodeCvt<char8_t>{}")]]
inline string WideStringToUTF8 (
const wstring& ws)
338 return WideStringToNarrow (ws, WellKnownCodePages::kUTF8);
341 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt")]] vector<byte>
342 MapUNICODETextToSerializedFormat (
const wchar_t* start,
const wchar_t* end, CodePage useCP = WellKnownCodePages::kUTF8);
344 [[deprecated (
"Since Stroika v3.0d2 - use CodeCvt")]] wstring MapUNICODETextWithMaybeBOMTowstring (
const char* start,
const char* end);
346 [[deprecated (
"Since Stroika v3.0d2 - use wstring{s.begin(), s.end()}")]]
inline wstring ASCIIStringToWide (
const string& s)
349 for (string::const_iterator i = s.begin (); i != s.end (); ++i) {
350 Assert (isascii (*i));
353 return wstring (s.begin (), s.end ());
355 [[deprecated (
"Since Stroika v3.0d2 - seems unneeded - use String{}.AsASCII() iuf needed}")]]
inline string WideStringToASCII (
const wstring& s)
358 for (wstring::const_iterator i = s.begin (); i != s.end (); ++i) {
359 Assert (isascii (*i));
362 DISABLE_COMPILER_MSC_WARNING_START (4244)
363 return
string{s.begin (), s.end ()};
364 DISABLE_COMPILER_MSC_WARNING_END (4244)
366 DISABLE_COMPILER_MSC_WARNING_END (4996);
367 DISABLE_COMPILER_GCC_WARNING_END (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
368 DISABLE_COMPILER_CLANG_WARNING_END (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
#define RequireNotNull(p)
DISABLE_COMPILER_MSC_WARNING_START(4996)