Plasma Engine  2.0
Loading...
Searching...
No Matches
StringBase.h
1#pragma once
2
3#include <Foundation/Strings/StringView.h>
4
5namespace plInternal
6{
7 template <typename T, bool isString>
9}
10
12template <typename Derived>
14{
15public:
20
22 bool IsEmpty() const; // [tested]
23
25 bool StartsWith(plStringView sStartsWith) const; // [tested]
26
28 bool StartsWith_NoCase(plStringView sStartsWith) const; // [tested]
29
31 bool EndsWith(plStringView sEndsWith) const; // [tested]
32
34 bool EndsWith_NoCase(plStringView sEndsWith) const; // [tested]
35
38 const char* FindSubString(plStringView sStringToFind, const char* szStartSearchAt = nullptr) const; // [tested]
39
42 const char* FindSubString_NoCase(plStringView sStringToFind, const char* szStartSearchAt = nullptr) const; // [tested]
43
46 const char* FindLastSubString(plStringView sStringToFind, const char* szStartSearchAt = nullptr) const; // [tested]
47
50 const char* FindLastSubString_NoCase(plStringView sStringToFind, const char* szStartSearchAt = nullptr) const; // [tested]
51
54 const char* FindWholeWord(const char* szSearchFor, plStringUtils::PL_CHARACTER_FILTER isDelimiterCB, const char* szStartSearchAt = nullptr) const; // [tested]
55
58 const char* FindWholeWord_NoCase(const char* szSearchFor, plStringUtils::PL_CHARACTER_FILTER isDelimiterCB, const char* szStartSearchAt = nullptr) const; // [tested]
59
61 plInt32 Compare(plStringView sOther) const; // [tested]
62
65 plInt32 CompareN(plStringView sOther, plUInt32 uiCharsToCompare) const; // [tested]
66
68 plInt32 Compare_NoCase(plStringView sOther) const; // [tested]
69
72 plInt32 CompareN_NoCase(plStringView sOther, plUInt32 uiCharsToCompare) const; // [tested]
73
75 bool IsEqual(plStringView sOther) const; // [tested]
76
78 bool IsEqualN(plStringView sOther, plUInt32 uiCharsToCompare) const; // [tested]
79
81 bool IsEqual_NoCase(plStringView sOther) const; // [tested]
82
84 bool IsEqualN_NoCase(plStringView sOther, plUInt32 uiCharsToCompare) const; // [tested]
85
87 const char* ComputeCharacterPosition(plUInt32 uiCharacterIndex) const;
88
94
100
102 operator plStringView() const; // [tested]
103
105 plStringView GetView() const; // [tested]
106
108 PL_ALWAYS_INLINE operator const char*() const { return InternalGetData(); }
109
115 template <typename Container>
116 void Split(bool bReturnEmptyStrings, Container& ref_output, const char* szSeparator1, const char* szSeparator2 = nullptr, const char* szSeparator3 = nullptr, const char* szSeparator4 = nullptr, const char* szSeparator5 = nullptr, const char* szSeparator6 = nullptr) const; // [tested]
117
119 bool HasAnyExtension() const; // [tested]
120
123 bool HasExtension(plStringView sExtension) const; // [tested]
124
126 plStringView GetFileExtension() const; // [tested]
127
131 plStringView GetFileName() const; // [tested]
132
136 plStringView GetFileNameAndExtension() const; // [tested]
137
145 plStringView GetFileDirectory() const; // [tested]
146
148 bool IsAbsolutePath() const; // [tested]
149
151 bool IsRelativePath() const; // [tested]
152
154 bool IsRootedPath() const; // [tested]
155
163 plStringView GetRootedPathRootName() const; // [tested]
164
165#if PL_ENABLED(PL_INTEROP_STL_STRINGS)
167 PL_ALWAYS_INLINE std::string_view GetAsStdView() const
168 {
169 return std::string_view(InternalGetData(), static_cast<size_t>(InternalGetElementCount()));
170 }
172 PL_ALWAYS_INLINE std::string GetAsStdString() const
173 {
174 return std::string(GetAsStdView());
175 }
176
178 PL_ALWAYS_INLINE operator std::string_view() const
179 {
180 return GetAsStdView();
181 }
182
184 PL_ALWAYS_INLINE operator std::string() const
185 {
186 return std::string(GetAsStdView());
187 }
188#endif
189
190private:
191 const char* InternalGetData() const;
192 const char* InternalGetDataEnd() const;
193 plUInt32 InternalGetElementCount() const;
194
195 template <typename Derived2>
196 friend typename plStringBase<Derived2>::iterator begin(const plStringBase<Derived2>& container);
197
198 template <typename Derived2>
199 friend typename plStringBase<Derived2>::const_iterator cbegin(const plStringBase<Derived2>& container);
200
201 template <typename Derived2>
202 friend typename plStringBase<Derived2>::iterator end(const plStringBase<Derived2>& container);
203
204 template <typename Derived2>
205 friend typename plStringBase<Derived2>::const_iterator cend(const plStringBase<Derived2>& container);
206
207 template <typename Derived2>
208 friend typename plStringBase<Derived2>::reverse_iterator rbegin(const plStringBase<Derived2>& container);
209
210 template <typename Derived2>
211 friend typename plStringBase<Derived2>::const_reverse_iterator crbegin(const plStringBase<Derived2>& container);
212
213 template <typename Derived2>
214 friend typename plStringBase<Derived2>::reverse_iterator rend(const plStringBase<Derived2>& container);
215
216 template <typename Derived2>
217 friend typename plStringBase<Derived2>::const_reverse_iterator crend(const plStringBase<Derived2>& container);
218};
219
220
221template <typename Derived>
222typename plStringBase<Derived>::iterator begin(const plStringBase<Derived>& container)
223{
224 return typename plStringBase<Derived>::iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetData());
225}
226
227template <typename Derived>
228typename plStringBase<Derived>::const_iterator cbegin(const plStringBase<Derived>& container)
229{
230 return typename plStringBase<Derived>::const_iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetData());
231}
232
233template <typename Derived>
234typename plStringBase<Derived>::iterator end(const plStringBase<Derived>& container)
235{
236 return typename plStringBase<Derived>::iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetDataEnd());
237}
238
239template <typename Derived>
241{
242 return typename plStringBase<Derived>::const_iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetDataEnd());
243}
244
245
246template <typename Derived>
248{
249 return typename plStringBase<Derived>::reverse_iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetDataEnd());
250}
251
252template <typename Derived>
254{
255 return typename plStringBase<Derived>::const_reverse_iterator(container.InternalGetData(), container.InternalGetDataEnd(), container.InternalGetDataEnd());
256}
257
258template <typename Derived>
260{
261 return typename plStringBase<Derived>::reverse_iterator(container.InternalGetData(), container.InternalGetDataEnd(), nullptr);
262}
263
264template <typename Derived>
266{
267 return typename plStringBase<Derived>::const_reverse_iterator(container.InternalGetData(), container.InternalGetDataEnd(), nullptr);
268}
269
270#include <Foundation/Strings/Implementation/StringBase_inl.h>
bool(*)(plUInt32 uiChar) PL_CHARACTER_FILTER
Function Definition for a function that determines whether a (Utf32) character belongs to a certain c...
Definition StringUtils.h:209
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Definition StringBase.h:8
Base class for strings, which implements all read-only string functions.
Definition StringBase.h:14
bool IsEqualN(plStringView sOther, plUInt32 uiCharsToCompare) const
Compares up to a given number of characters of this string with the other string for equality....
Definition StringBase_inl.h:153
bool IsAbsolutePath() const
Returns true, if the given path represents an absolute path on the current OS.
Definition StringBase_inl.h:360
const char * FindLastSubString(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:77
bool IsRelativePath() const
Returns true, if the given path represents a relative path on the current OS.
Definition StringBase_inl.h:354
plInt32 CompareN_NoCase(plStringView sOther, plUInt32 uiCharsToCompare) const
Definition StringBase_inl.h:141
bool StartsWith_NoCase(plStringView sStartsWith) const
Returns true, if this string starts with the given string. Case insensitive.
Definition StringBase_inl.h:37
const char * FindLastSubString_NoCase(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:89
plStringView GetFileNameAndExtension() const
Returns the substring that represents the file name including the file extension.
Definition StringBase_inl.h:372
bool IsEqualN_NoCase(plStringView sOther, plUInt32 uiCharsToCompare) const
Compares up to a given number of characters of this string with the other string for equality....
Definition StringBase_inl.h:165
bool StartsWith(plStringView sStartsWith) const
Returns true, if this string starts with the given string.
Definition StringBase_inl.h:31
plInt32 Compare(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringBase_inl.h:123
bool IsEmpty() const
Returns whether the string is an empty string.
Definition StringBase_inl.h:25
const char * FindSubString_NoCase(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:66
bool EndsWith_NoCase(plStringView sEndsWith) const
Returns true, if this string ends with the given string. Case insensitive.
Definition StringBase_inl.h:49
plStringView GetFileName() const
Returns the file name of a path, excluding the path and extension.
Definition StringBase_inl.h:378
const char * FindWholeWord_NoCase(const char *szSearchFor, plStringUtils::PL_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:112
plInt32 Compare_NoCase(plStringView sOther) const
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller',...
Definition StringBase_inl.h:135
bool IsEqual(plStringView sOther) const
Compares this string with the other string for equality.
Definition StringBase_inl.h:147
plInt32 CompareN(plStringView sOther, plUInt32 uiCharsToCompare) const
Definition StringBase_inl.h:129
plStringView GetRootedPathRootName() const
Extracts the root name from a rooted path.
Definition StringBase_inl.h:342
reverse_iterator GetIteratorBack() const
Returns an iterator to this string, which points to the very last character (NOT the end).
Definition StringBase_inl.h:187
bool HasAnyExtension() const
Checks whether the given path has any file extension.
Definition StringBase_inl.h:396
void Split(bool bReturnEmptyStrings, Container &ref_output, const char *szSeparator1, const char *szSeparator2=nullptr, const char *szSeparator3=nullptr, const char *szSeparator4=nullptr, const char *szSeparator5=nullptr, const char *szSeparator6=nullptr) const
Fills the given container with plStringView's which represent each found substring....
Definition StringBase_inl.h:336
const char * ComputeCharacterPosition(plUInt32 uiCharacterIndex) const
Computes the pointer to the n-th character in the string. This is a linear search from the start.
Definition StringBase_inl.h:171
bool EndsWith(plStringView sEndsWith) const
Returns true, if this string ends with the given string.
Definition StringBase_inl.h:43
bool HasExtension(plStringView sExtension) const
Checks whether the given path ends with the given extension. szExtension should start with a '....
Definition StringBase_inl.h:390
iterator GetIteratorFront() const
Returns an iterator to this string, which points to the very first character.
Definition StringBase_inl.h:181
plStringView GetFileExtension() const
Returns the file extension of the given path. Will be empty, if the path does not end with a proper e...
Definition StringBase_inl.h:384
bool IsEqual_NoCase(plStringView sOther) const
Compares this string with the other string for equality.
Definition StringBase_inl.h:159
plStringView GetFileDirectory() const
Returns the directory of the given file, which is the substring up to the last path separator.
Definition StringBase_inl.h:366
plStringView GetView() const
Returns a string view to this string's data.
Definition StringBase_inl.h:329
bool IsRootedPath() const
Returns true, if the given path represents a 'rooted' path. See plFileSystem for details.
Definition StringBase_inl.h:348
const char * FindWholeWord(const char *szSearchFor, plStringUtils::PL_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:101
const char * FindSubString(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringBase_inl.h:55
STL forward iterator used by all string classes. Iterates over unicode characters....
Definition StringIterator.h:10
STL reverse iterator used by all string classes. Iterates over unicode characters....
Definition StringIterator.h:163
Base class which marks a class as containing string data.
Definition StringView.h:19