Plasma Engine  2.0
Loading...
Searching...
No Matches
String.h
1#pragma once
2
3#include <Foundation/Algorithm/HashingUtils.h>
4#include <Foundation/Containers/HybridArray.h>
5#include <Foundation/Strings/Implementation/StringBase.h>
6#include <Foundation/Strings/StringConversion.h>
7#include <Foundation/Strings/StringUtils.h>
8#include <Foundation/Strings/StringView.h>
9
10class plStringBuilder;
11class plStreamReader;
12
26template <plUInt16 Size>
27struct plHybridStringBase : public plStringBase<plHybridStringBase<Size>>
28{
29protected:
31 plHybridStringBase(plAllocator* pAllocator); // [tested]
32
34 plHybridStringBase(const plHybridStringBase& rhs, plAllocator* pAllocator); // [tested]
35
37 plHybridStringBase(plHybridStringBase&& rhs, plAllocator* pAllocator); // [tested]
38
40 plHybridStringBase(const char* rhs, plAllocator* pAllocator); // [tested]
41
43 plHybridStringBase(const wchar_t* rhs, plAllocator* pAllocator); // [tested]
44
46 plHybridStringBase(const plStringView& rhs, plAllocator* pAllocator); // [tested]
47
49 plHybridStringBase(const plStringBuilder& rhs, plAllocator* pAllocator); // [tested]
50
52 plHybridStringBase(plStringBuilder&& rhs, plAllocator* pAllocator); // [tested]
53
55 ~plHybridStringBase(); // [tested]
56
58 void operator=(const plHybridStringBase& rhs); // [tested]
59
61 void operator=(plHybridStringBase&& rhs); // [tested]
62
64 void operator=(const char* rhs); // [tested]
65
67 void operator=(const wchar_t* rhs); // [tested]
68
70 void operator=(const plStringView& rhs); // [tested]
71
73 void operator=(const plStringBuilder& rhs); // [tested]
74
76 void operator=(plStringBuilder&& rhs); // [tested]
77
78#if PL_ENABLED(PL_INTEROP_STL_STRINGS)
80 plHybridStringBase(const std::string_view& rhs, plAllocator* pAllocator);
81
83 plHybridStringBase(const std::string& rhs, plAllocator* pAllocator);
84
86 void operator=(const std::string_view& rhs);
87
89 void operator=(const std::string& rhs);
90#endif
91
92public:
96 void Clear(); // [tested]
97
99 const char* GetData() const; // [tested]
100
102 plUInt32 GetElementCount() const; // [tested]
103
109 plUInt32 GetCharacterCount() const; // [tested]
110
116 plStringView GetSubString(plUInt32 uiFirstCharacter, plUInt32 uiNumCharacters) const; // [tested]
117
122 plStringView GetFirst(plUInt32 uiNumCharacters) const; // [tested]
123
128 plStringView GetLast(plUInt32 uiNumCharacters) const; // [tested]
129
131 void ReadAll(plStreamReader& inout_stream);
132
134 plUInt64 GetHeapMemoryUsage() const { return m_Data.GetHeapMemoryUsage(); }
135
136private:
137 friend class plStringBuilder;
138
140};
141
142
144template <plUInt16 Size, typename AllocatorWrapper = plDefaultAllocatorWrapper>
146{
147public:
149 plHybridString(plAllocator* pAllocator);
150
153 plHybridString(const char* rhs);
154 plHybridString(const wchar_t* rhs);
155 plHybridString(const plStringView& rhs);
160
161 void operator=(const plHybridString<Size, AllocatorWrapper>& rhs);
162 void operator=(const plHybridStringBase<Size>& rhs);
163 void operator=(const char* szString);
164 void operator=(const wchar_t* pString);
165 void operator=(const plStringView& rhs);
166 void operator=(const plStringBuilder& rhs);
167 void operator=(plStringBuilder&& rhs);
168 void operator=(plHybridString<Size, AllocatorWrapper>&& rhs);
169 void operator=(plHybridStringBase<Size>&& rhs);
170
171#if PL_ENABLED(PL_INTEROP_STL_STRINGS)
172 plHybridString(const std::string_view& rhs);
173 plHybridString(const std::string& rhs);
174 void operator=(const std::string_view& rhs);
175 void operator=(const std::string& rhs);
176#endif
177};
178
181
191
192static_assert(plGetTypeClass<plString>::value == plTypeIsClass::value);
193
194template <plUInt16 Size>
196{
197 static PL_ALWAYS_INLINE bool Less(plStringView lhs, plStringView rhs)
198 {
199 return lhs.Compare(rhs) < 0;
200 }
201
202 static PL_ALWAYS_INLINE bool Equal(plStringView lhs, plStringView rhs)
203 {
204 return lhs.IsEqual(rhs);
205 }
206};
207
209{
210 static PL_ALWAYS_INLINE bool Less(plStringView lhs, plStringView rhs)
211 {
212 return lhs.Compare_NoCase(rhs) < 0;
213 }
214
215 static PL_ALWAYS_INLINE bool Equal(plStringView lhs, plStringView rhs)
216 {
217 return lhs.IsEqual_NoCase(rhs);
218 }
219};
220
222{
224 static PL_ALWAYS_INLINE bool Less(const char* a, const char* b) { return plStringUtils::Compare(a, b) < 0; }
225
227 static PL_ALWAYS_INLINE bool Equal(const char* a, const char* b) { return plStringUtils::IsEqual(a, b); }
228};
229
230// For plFormatString
231PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plString& sArg);
232PL_FOUNDATION_DLL plStringView BuildString(char* szTmp, plUInt32 uiLength, const plUntrackedString& sArg);
233
234#include <Foundation/Strings/Implementation/String_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition DynamicArray_inl.h:234
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Interface for binary in (read) streams.
Definition Stream.h:22
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
static bool IsEqual(const char *pString1, const char *pString2, const char *pString1End=plUnicodeUtils::GetMaxStringEnd< char >(), const char *pString2End=plUnicodeUtils::GetMaxStringEnd< char >())
Returns true, if the two given strings are identical (bitwise).
Definition StringUtils_inl.h:125
static plInt32 Compare(const char *pString1, const char *pString2, const char *pString1End=plUnicodeUtils::GetMaxStringEnd< char >(), const char *pString2End=plUnicodeUtils::GetMaxStringEnd< char >())
Compares two strings for equality.
Definition StringUtils.cpp:218
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
bool IsEqual_NoCase(plStringView sOther) const
Compares this string view with the other string view for equality.
Definition StringView_inl.h:95
plInt32 Compare_NoCase(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringView.cpp:41
plInt32 Compare(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringView.cpp:31
bool IsEqual(plStringView sOther) const
Compares this string view with the other string view for equality.
Definition StringView_inl.h:90
Definition String.h:222
static PL_ALWAYS_INLINE bool Less(const char *a, const char *b)
Returns true if a is less than b.
Definition String.h:224
static PL_ALWAYS_INLINE bool Equal(const char *a, const char *b)
Returns true if a is equal to b.
Definition String.h:227
A comparer object is used in sorting algorithms to compare to objects of the same type.
Definition Comparer.h:7
PL_ALWAYS_INLINE bool Less(const T &a, const T &b) const
Returns true if a is less than b.
Definition Comparer.h:9
Definition String.h:209
If there is an % operator which takes a plTypeIsMemRelocatable and returns a CompileTimeTrueType T is...
Definition TypeTraits.h:67
A string class for storing and passing around strings.
Definition String.h:28
plHybridStringBase(plAllocator *pAllocator)
Creates an empty string.
Definition String_inl.h:4
const char * GetData() const
Returns a pointer to the internal Utf8 string.
Definition String_inl.h:56
plUInt32 GetElementCount() const
Returns the amount of bytes that this string takes (excluding the '\0' terminator).
Definition String_inl.h:65
plStringView GetFirst(plUInt32 uiNumCharacters) const
Returns a view to the sub-string containing the first uiNumCharacters characters of this string.
Definition String_inl.h:144
plUInt32 GetCharacterCount() const
Returns the number of characters in this string. Might be less than GetElementCount,...
Definition String_inl.h:71
~plHybridStringBase()
Destructor.
plStringView GetSubString(plUInt32 uiFirstCharacter, plUInt32 uiNumCharacters) const
Returns a view to a sub-string of this string, starting at character uiFirstCharacter,...
Definition String_inl.h:131
void ReadAll(plStreamReader &inout_stream)
Replaces the current string with the content from the stream. Reads the stream to its end.
Definition AllStrings_inl.h:58
void Clear()
Resets this string to an empty string.
Definition String_inl.h:49
void operator=(const plHybridStringBase &rhs)
Copies the data from rhs.
Definition String_inl.h:96
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition String.h:134
plStringView GetLast(plUInt32 uiNumCharacters) const
Returns a view to the sub-string containing the last uiNumCharacters characters of this string.
Definition String_inl.h:150
Definition String.h:146
Base class for strings, which implements all read-only string functions.
Definition StringBase.h:14