Plasma Engine  2.0
Loading...
Searching...
No Matches
StringConversion.h
1#pragma once
2
3#include <Foundation/Containers/HybridArray.h>
4#include <Foundation/Strings/StringView.h>
5
6#if PL_ENABLED(PL_PLATFORM_WINDOWS_UWP)
7// Include our windows.h header first to get rid of defines.
8# include <Foundation/Basics/Platform/Win/IncludeWindows.h>
9// For HString, HStringReference and co.
10# include <wrl/wrappers/corewrappers.h>
11#endif
12
19class PL_FOUNDATION_DLL plStringWChar
20{
21public:
23 plStringWChar(const plUInt16* pUtf16, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
24 plStringWChar(const plUInt32* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
25 plStringWChar(const wchar_t* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
27
28 void operator=(const plUInt16* pUtf16);
29 void operator=(const plUInt32* pUtf32);
30 void operator=(const wchar_t* pUtf32);
31 void operator=(plStringView sUtf8);
32
33 PL_ALWAYS_INLINE operator const wchar_t*() const { return &m_Data[0]; }
34 PL_ALWAYS_INLINE const wchar_t* GetData() const { return &m_Data[0]; }
35 PL_ALWAYS_INLINE plUInt32 GetElementCount() const { return m_Data.GetCount() - 1; /* exclude the '\0' terminator */ }
36
37private:
38 static constexpr plUInt32 BufferSize = 1024;
40};
41
42
46class PL_FOUNDATION_DLL plStringUtf8
47{
48public:
50 plStringUtf8(const char* szUtf8, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
51 plStringUtf8(const plUInt16* pUtf16, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
52 plStringUtf8(const plUInt32* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
53 plStringUtf8(const wchar_t* pWChar, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
54
55#if PL_ENABLED(PL_PLATFORM_WINDOWS_UWP)
56 plStringUtf8(const Microsoft::WRL::Wrappers::HString& hstring, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
57 plStringUtf8(const HSTRING& hstring, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
58#endif
59
60 void operator=(const char* szUtf8);
61 void operator=(const plUInt16* pUtf16);
62 void operator=(const plUInt32* pUtf32);
63 void operator=(const wchar_t* pWChar);
64
65#if PL_ENABLED(PL_PLATFORM_WINDOWS_UWP)
66 void operator=(const Microsoft::WRL::Wrappers::HString& hstring);
67 void operator=(const HSTRING& hstring);
68#endif
69
70 PL_ALWAYS_INLINE operator const char*() const
71 {
72 return &m_Data[0];
73 }
74 PL_ALWAYS_INLINE const char* GetData() const
75 {
76 return &m_Data[0];
77 }
78 PL_ALWAYS_INLINE plUInt32 GetElementCount() const
79 {
80 return m_Data.GetCount() - 1; /* exclude the '\0' terminator */
81 }
82 PL_ALWAYS_INLINE operator plStringView() const
83 {
84 return GetView();
85 }
86 PL_ALWAYS_INLINE plStringView GetView() const
87 {
88 return plStringView(&m_Data[0], GetElementCount());
89 }
90
91private:
92 static constexpr plUInt32 BufferSize = 1024;
94};
95
96
97
103class PL_FOUNDATION_DLL plStringUtf16
104{
105public:
107 plStringUtf16(const char* szUtf8, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
108 plStringUtf16(const plUInt16* pUtf16, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
109 plStringUtf16(const plUInt32* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
110 plStringUtf16(const wchar_t* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
111
112 void operator=(const char* szUtf8);
113 void operator=(const plUInt16* pUtf16);
114 void operator=(const plUInt32* pUtf32);
115 void operator=(const wchar_t* pUtf32);
116
117 PL_ALWAYS_INLINE const plUInt16* GetData() const { return &m_Data[0]; }
118 PL_ALWAYS_INLINE plUInt32 GetElementCount() const { return m_Data.GetCount() - 1; /* exclude the '\0' terminator */ }
119
120private:
121 static constexpr plUInt32 BufferSize = 1024;
123};
124
125
126
130class PL_FOUNDATION_DLL plStringUtf32
131{
132public:
134 plStringUtf32(const char* szUtf8, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
135 plStringUtf32(const plUInt16* pUtf16, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
136 plStringUtf32(const plUInt32* pUtf32, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
137 plStringUtf32(const wchar_t* pWChar, plAllocator* pAllocator = plFoundation::GetDefaultAllocator());
138
139 void operator=(const char* szUtf8);
140 void operator=(const plUInt16* pUtf16);
141 void operator=(const plUInt32* pUtf32);
142 void operator=(const wchar_t* pWChar);
143
144 PL_ALWAYS_INLINE const plUInt32* GetData() const { return &m_Data[0]; }
145 PL_ALWAYS_INLINE plUInt32 GetElementCount() const { return m_Data.GetCount() - 1; /* exclude the '\0' terminator */ }
146
147private:
148 static constexpr plUInt32 BufferSize = 1024;
150};
151
152
153#if PL_ENABLED(PL_PLATFORM_WINDOWS_UWP)
154
159class PL_FOUNDATION_DLL plStringHString
160{
161public:
162 plStringHString();
163 plStringHString(const char* szUtf8);
164 plStringHString(const plUInt16* szUtf16);
165 plStringHString(const plUInt32* szUtf32);
166 plStringHString(const wchar_t* szWChar);
167
168 void operator=(const char* szUtf8);
169 void operator=(const plUInt16* szUtf16);
170 void operator=(const plUInt32* szUtf32);
171 void operator=(const wchar_t* szWChar);
172
175 PL_ALWAYS_INLINE const Microsoft::WRL::Wrappers::HString& GetData() const { return m_Data; }
176
177private:
178 Microsoft::WRL::Wrappers::HString m_Data;
179};
180
181#endif
182
183
184#include <Foundation/Strings/Implementation/StringConversion_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
static PL_ALWAYS_INLINE plAllocator * GetDefaultAllocator()
The default allocator can be used for any kind of allocation if no alignment is required.
Definition Basics.h:82
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
A very simple class to convert text to Utf16 encoding.
Definition StringConversion.h:104
This class only exists for completeness.
Definition StringConversion.h:131
A small string class that converts any other encoding to Utf8.
Definition StringConversion.h:47
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A very simple string class that should only be used to temporarily convert text to the OSes native wc...
Definition StringConversion.h:20