Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SDKString.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Configuration_SDKString_h_
5#define _Stroika_Foundation_Configuration_SDKString_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <span>
10#include <string>
11
12#include "Stroika/Foundation/Characters/SDKChar.h"
13
14/**
15 * TODO
16 * @todo CONSIDER directly documenting/supporting EUC - https://en.wikipedia.org/wiki/Extended_Unix_Code as alternate for non-unicode systems
17 */
18
20
21 /**
22 * This is the kind of String passed to most platform APIs.
23 *
24 * The easiest way to convert between a String and SDKString, is via the String class APIs:
25 * AsSDKString, AsNarrowSDKString, FromSDKString, FromNarrowSDKString.
26 *
27 * For std::string (etc) interop, that works, but also @SDK2Narrow and @Narrow2SDK
28 *
29 * @see SDKChar
30 *
31 * Notes:
32 * NOTE - in the context of this file, the word "Narrow" refers to single byte encodings of UNICODE
33 * characters (such as SJIS, UTF-8, or ISO-Latin-1, for example).
34 *
35 * NOTE - in the context of this file, the word "Wide" refers to wchar_t based encoding of UNICODE
36 * characters.
37 */
38 using SDKString = basic_string<SDKChar>;
39
40 /**
41 * SDKSTR is a macro to wrap constant string literals to get const SDKChar*
42 */
43#if qTargetPlatformSDKUseswchar_t
44#define SDKSTR(x) L##x
45#else
46#define SDKSTR(x) x
47#endif
48
49 /**
50 * This flag ignores missing code points (when transforming from UNICODE to some character set that might not contain them),
51 * and does the best possible to map characters. Needed for things like translating a UNICODE error message to a locale{}
52 * character set which might not contain some of those UNICODE characters.
53 */
55 eIgnoreErrors
56 };
57 using AllowMissingCharacterErrorsFlag::eIgnoreErrors;
58
59 /**
60 * Convert string/span of 'char' - interpreting the char in the locale/active code page of the current
61 * operating systems (@see SDKChar).
62 *
63 * On most platforms, this does nothing, but on Windows, it maps strings to wstring using code-page CP_ACP
64 *
65 * Characters with (detectibly) missing code-points will generate an exception, unless AllowMissingCharacterErrorsFlag is
66 * specified (but exceptions can happen in any case due to possible bad_alloc).
67 */
68 SDKString Narrow2SDK (span<const char> s);
69 SDKString Narrow2SDK (const string& s);
72
73 /**
74 * Interpret the narrow string in the SDKChar manner (locale/charset) and convert to UNICODE wstring.
75 *
76 * This is identical to SDK2Wide () if SDKChar==char (e.g. on Unix).
77 *
78 * Characters with (detectibly) missing code-points will generate an exception, unless AllowMissingCharacterErrorsFlag is
79 * specified (but exceptions can happen in any case due to possible bad_alloc).
80 */
81 wstring NarrowSDK2Wide (span<const char> s);
82 wstring NarrowSDK2Wide (const string& s);
83 wstring NarrowSDK2Wide (span<const char> s, AllowMissingCharacterErrorsFlag);
84 wstring NarrowSDK2Wide (const string& s, AllowMissingCharacterErrorsFlag);
85
86 /**
87 * Interpret the string/span of SDKChar (@see SDKChar) - and convert it to narrow 'char' using the current code-page/locale.
88 *
89 * On most platforms, this does nothing, but on Windows, it maps wstrings to string using code-page CP_ACP
90 *
91 * Characters with (detectibly) missing code-points will generate an exception, unless AllowMissingCharacterErrorsFlag is
92 * specified (but exceptions can happen in any case due to possible bad_alloc).
93 */
94 string SDK2Narrow (span<const SDKChar> s);
95 string SDK2Narrow (const SDKString& s);
96 string SDK2Narrow (span<const SDKChar> s, AllowMissingCharacterErrorsFlag);
98
99 /**
100 * Interpret the string/span of SDKChar (@see SDKChar) - and convert it to UNICODE 'wchar_t' string using the current code-page/locale.
101 *
102 * On Windows, this does nothing as SDKString==wstring, but on other platforms it follows the rules of SDKChar to map it to wstring.
103 *
104 * Characters with (detectibly) missing code-points will generate an exception, unless AllowMissingCharacterErrorsFlag is
105 * specified (but exceptions can happen in any case due to possible bad_alloc).
106 */
107 wstring SDK2Wide (span<const SDKChar> s);
108 wstring SDK2Wide (const SDKString& s);
109 wstring SDK2Wide (span<const SDKChar> s, AllowMissingCharacterErrorsFlag);
111
112 /**
113 * Interpret the string/span of UNICODE wchar_t - and convert it an SDKString string, using the current locale/SDKChar/SDKString rules.
114 *
115 * On Windows, this does nothing as SDKString==wstring, but on other platforms it follows the rules of SDKChar to map it from wstring.
116 *
117 * Characters with (detectibly) missing code-points will generate an exception, unless AllowMissingCharacterErrorsFlag is
118 * specified (but exceptions can happen in any case due to possible bad_alloc).
119 */
120 SDKString Wide2SDK (span<const wchar_t> s);
121 SDKString Wide2SDK (const wstring& s);
122 SDKString Wide2SDK (span<const wchar_t> s, AllowMissingCharacterErrorsFlag);
124
125}
126
127/*
128 ********************************************************************************
129 ***************************** Implementation Details ***************************
130 ********************************************************************************
131 */
132#include "SDKString.inl"
133
134#endif /*_Stroika_Foundation_Configuration_SDKString_h_*/
wstring NarrowSDK2Wide(span< const char > s)
Definition SDKString.inl:81
SDKString Wide2SDK(span< const wchar_t > s)
Definition SDKString.cpp:58
wstring SDK2Wide(span< const SDKChar > s)
basic_string< SDKChar > SDKString
Definition SDKString.h:38
SDKString Narrow2SDK(span< const char > s)
Definition SDKString.inl:19
string SDK2Narrow(span< const SDKChar > s)