7 , m_uiElementCount(
plStringUtils::GetStringElementCount(pStart))
12constexpr PL_ALWAYS_INLINE
plStringView::plStringView(T pStart,
typename std::enable_if<std::is_same<T, const char*>::value,
int>::type*)
14 , m_uiElementCount(
plStringUtils::GetStringElementCount(pStart))
19constexpr PL_ALWAYS_INLINE
plStringView::plStringView(
const T&& str,
typename std::enable_if<std::is_same<T, const char*>::value ==
false && std::is_convertible<T, const char*>::value,
int>::type*)
27 PL_ASSERT_DEBUG(pStart <= pEnd,
"Invalid pointers to construct a string view from.");
30 m_uiElementCount =
static_cast<plUInt32
>(pEnd - pStart);
35 , m_uiElementCount(uiLength)
42 , m_uiElementCount(N - 1)
44 static_assert(N > 0,
"Not a string literal");
59 const char* pEnd = m_pStart + m_uiElementCount;
61 m_uiElementCount =
static_cast<plUInt32
>(pEnd - m_pStart);
66 const char* pEnd = m_pStart + m_uiElementCount;
68 m_uiElementCount =
static_cast<plUInt32
>(pEnd - m_pStart);
73 return (m_pStart !=
nullptr) && (m_uiElementCount > 0);
78 PL_ASSERT_DEV((szCurPos >= m_pStart) && (szCurPos <= m_pStart + m_uiElementCount),
"New start position must still be inside the view's range.");
80 const char* pEnd = m_pStart + m_uiElementCount;
82 m_uiElementCount =
static_cast<plUInt32
>(pEnd - m_pStart);
87 return m_uiElementCount == 0;
122 return Trim(szTrimChars, szTrimChars);
129 const char* pEnd = m_pStart + m_uiElementCount;
131 m_uiElementCount =
static_cast<plUInt32
>(pEnd - m_pStart);
135constexpr PL_ALWAYS_INLINE
plStringView operator"" _plsv(
const char* pString,
size_t uiLen)
137 return plStringView(pString,
static_cast<plUInt32
>(uiLen));
140template <
typename Container>
141void plStringView::Split(
bool bReturnEmptyStrings, Container& ref_output,
const char* szSeparator1,
const char* szSeparator2 ,
const char* szSeparator3 ,
const char* szSeparator4 ,
const char* szSeparator5 ,
const char* szSeparator6 )
const
148 const plUInt32 uiParams = 6;
150 const plStringView seps[uiParams] = {szSeparator1, szSeparator2, szSeparator3, szSeparator4, szSeparator5, szSeparator6};
157 plUInt32 uiFoundSeparator = 0;
159 for (plUInt32 i = 0; i < uiParams; ++i)
163 if ((szFound !=
nullptr) && (szFound < szFoundPos))
165 szFoundPos = szFound;
166 uiFoundSeparator = i;
175 if (bReturnEmptyStrings || (uiLen > 0))
176 ref_output.PushBack(
plStringView(szReadPos, szReadPos + uiLen));
181 if (bReturnEmptyStrings || (szFoundPos > szReadPos))
182 ref_output.PushBack(
plStringView(szReadPos, szFoundPos));
193#if PL_DISABLED(PL_USE_CPP20_OPERATORS)
202#if PL_ENABLED(PL_USE_CPP20_OPERATORS)
Helper functions to work with UTF-8 strings (which include pure ASCII strings)
Definition StringUtils.h:11
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 bool IsEqual_NoCase(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 (case-insensitive).
Definition StringUtils_inl.h:136
static bool EndsWith_NoCase(const char *szString, const char *szEndsWith, const char *pStringEnd=plUnicodeUtils::GetMaxStringEnd< char >(), const char *szEndsWithEnd=plUnicodeUtils::GetMaxStringEnd< char >())
Returns true if szString ends with the string given in szEndsWith. Ignores case.
Definition StringUtils.cpp:517
static const char * FindSubString(const char *szSource, const char *szStringToFind, const char *pSourceEnd=plUnicodeUtils::GetMaxStringEnd< char >(), const char *szStringToFindEnd=plUnicodeUtils::GetMaxStringEnd< char >())
Searches for the first occurrence of szStringToFind in szSource.
Definition StringUtils.cpp:550
static bool EndsWith(const char *szString, const char *szEndsWith, const char *pStringEnd=plUnicodeUtils::GetMaxStringEnd< char >(), const char *szEndsWithEnd=plUnicodeUtils::GetMaxStringEnd< char >())
Returns true if szString ends with the string given in szEndsWith.
Definition StringUtils.cpp:501
static bool StartsWith(const char *szString, const char *szStartsWith, const char *pStringEnd=plUnicodeUtils::GetMaxStringEnd< char >(), const char *szStartsWithEnd=plUnicodeUtils::GetMaxStringEnd< char >())
Returns true if szString starts with the string given in szStartsWith.
Definition StringUtils.cpp:453
static constexpr plUInt32 GetStringElementCount(const T *pString)
Returns the number of elements of type T that the string contains, until it hits an element that is z...
Definition StringUtils_inl.h:45
static void Trim(const char *&ref_pString, const char *&ref_pStringEnd, const char *szTrimCharsStart, const char *szTrimCharsEnd)
Removes all characters at the start and end of the string that match the respective characters and up...
Definition StringUtils.cpp:794
static bool StartsWith_NoCase(const char *szString, const char *szStartsWith, const char *pStringEnd=plUnicodeUtils::GetMaxStringEnd< char >(), const char *szStartsWithEnd=plUnicodeUtils::GetMaxStringEnd< char >())
Returns true if szString starts with the string given in szStartsWith. Ignores case.
Definition StringUtils.cpp:477
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
bool StartsWith(plStringView sStartsWith) const
Returns true, if this string starts with the given string.
Definition StringView_inl.h:100
plUInt32 GetElementCount() const
Returns the number of bytes from the start position up to its end.
Definition StringView.h:93
void operator++()
Advances the start to the next character, unless the end of the range was reached.
Definition StringView_inl.h:54
void operator+=(plUInt32 d)
Advances the start forwards by d characters. Does not move it beyond the range's end.
Definition StringView_inl.h:64
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 StringView_inl.h:141
void Trim(const char *szTrimChars)
Removes all characters from the start and end that appear in the given strings by adjusting the begin...
Definition StringView_inl.h:120
const char * GetEndPointer() const
Returns the end of the view range. This will point to the byte AFTER the last character.
Definition StringView.h:108
bool EndsWith(plStringView sEndsWith) const
Returns true, if this string ends with the given string.
Definition StringView_inl.h:110
bool EndsWith_NoCase(plStringView sEndsWith) const
Returns true, if this string ends with the given string. Case insensitive.
Definition StringView_inl.h:115
bool StartsWith_NoCase(plStringView sStartsWith) const
Returns true, if this string starts with the given string. Case insensitive.
Definition StringView_inl.h:105
bool IsValid() const
Returns true, if the current string pointed to is non empty.
Definition StringView_inl.h:71
const char * GetStartPointer() const
Returns the start of the view range.
Definition StringView.h:102
bool IsEqual_NoCase(plStringView sOther) const
Compares this string view with the other string view for equality.
Definition StringView_inl.h:95
void SetStartPosition(const char *szCurPos)
Allows to set the start position to a different value.
Definition StringView_inl.h:76
constexpr plStringView()
Default constructor creates an invalid view.
bool IsEmpty() const
Returns whether the string is an empty string.
Definition StringView_inl.h:85
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
static constexpr T * GetMaxStringEnd()
[internal] Returns the max string end pointer for the given type
Definition UnicodeUtils_inl.h:261
static plResult MoveToNextUtf8(const char *&ref_szUtf8, plUInt32 uiNumCharacters=1)
Moves the given string pointer ahead to the next Utf8 character sequence.
Definition UnicodeUtils_inl.h:201
PL_ALWAYS_INLINE void IgnoreResult()
Used to silence compiler warnings, when success or failure doesn't matter.
Definition Types.h:69