ezEngine  Milestone 7
StringBase_inl.h
1 #pragma once
2 
3 template <typename Derived>
4 EZ_FORCE_INLINE const char* ezStringBase<Derived>::InternalGetData() const
5 {
6  const Derived* pDerived = static_cast<const Derived*>(this);
7  return pDerived->GetData();
8 }
9 
10 template <typename Derived>
11 EZ_FORCE_INLINE const char* ezStringBase<Derived>::InternalGetDataEnd() const
12 {
13  const Derived* pDerived = static_cast<const Derived*>(this);
14  return pDerived->GetData() + pDerived->GetElementCount();
15 }
16 
17 template <typename Derived>
18 EZ_FORCE_INLINE ezUInt32 ezStringBase<Derived>::InternalGetElementCount() const
19 {
20  const Derived* pDerived = static_cast<const Derived*>(this);
21  return pDerived->GetElementCount();
22 }
23 
24 template <typename Derived>
25 EZ_FORCE_INLINE bool ezStringBase<Derived>::IsEmpty() const
26 {
27  return ezStringUtils::IsNullOrEmpty(InternalGetData()) || (InternalGetData() == InternalGetDataEnd());
28 }
29 
30 template <typename Derived>
31 bool ezStringBase<Derived>::StartsWith(const char* szStartsWith) const
32 {
33  return ezStringUtils::StartsWith(InternalGetData(), szStartsWith, InternalGetDataEnd());
34 }
35 
36 template <typename Derived>
37 bool ezStringBase<Derived>::StartsWith_NoCase(const char* szStartsWith) const
38 {
39  return ezStringUtils::StartsWith_NoCase(InternalGetData(), szStartsWith, InternalGetDataEnd());
40 }
41 
42 template <typename Derived>
43 bool ezStringBase<Derived>::EndsWith(const char* szEndsWith) const
44 {
45  return ezStringUtils::EndsWith(InternalGetData(), szEndsWith, InternalGetDataEnd());
46 }
47 
48 template <typename Derived>
49 bool ezStringBase<Derived>::EndsWith_NoCase(const char* szEndsWith) const
50 {
51  return ezStringUtils::EndsWith_NoCase(InternalGetData(), szEndsWith, InternalGetDataEnd());
52 }
53 
54 template <typename Derived>
55 const char* ezStringBase<Derived>::FindSubString(const char* szStringToFind, const char* szStartSearchAt /* = nullptr */) const
56 {
57  if (szStartSearchAt == nullptr)
58  szStartSearchAt = InternalGetData();
59 
60  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
61 
62  return ezStringUtils::FindSubString(szStartSearchAt, szStringToFind, InternalGetDataEnd());
63 }
64 
65 template <typename Derived>
66 const char* ezStringBase<Derived>::FindSubString_NoCase(const char* szStringToFind, const char* szStartSearchAt /* = nullptr */) const
67 {
68  if (szStartSearchAt == nullptr)
69  szStartSearchAt = InternalGetData();
70 
71  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
72 
73  return ezStringUtils::FindSubString_NoCase(szStartSearchAt, szStringToFind, InternalGetDataEnd());
74 }
75 
76 template <typename Derived>
77 inline const char* ezStringBase<Derived>::FindLastSubString(const char* szStringToFind, const char* szStartSearchAt /* = nullptr */) const
78 {
79  if (szStartSearchAt == nullptr)
80  szStartSearchAt = InternalGetDataEnd();
81 
82  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
83 
84  return ezStringUtils::FindLastSubString(InternalGetData(), szStringToFind, szStartSearchAt, InternalGetDataEnd());
85 }
86 
87 template <typename Derived>
88 inline const char* ezStringBase<Derived>::FindLastSubString_NoCase(const char* szStringToFind, const char* szStartSearchAt /* = nullptr */) const
89 {
90  if (szStartSearchAt == nullptr)
91  szStartSearchAt = InternalGetDataEnd();
92 
93  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
94 
95  return ezStringUtils::FindLastSubString_NoCase(InternalGetData(), szStringToFind, szStartSearchAt, InternalGetDataEnd());
96 }
97 
98 template <typename Derived>
99 inline const char* ezStringBase<Derived>::FindWholeWord(const char* szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER IsDelimiterCB, const char* szStartSearchAt /* = nullptr */) const
100 {
101  if (szStartSearchAt == nullptr)
102  szStartSearchAt = InternalGetData();
103 
104  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
105 
106  return ezStringUtils::FindWholeWord(szStartSearchAt, szSearchFor, IsDelimiterCB, InternalGetDataEnd());
107 }
108 
109 template <typename Derived>
110 inline const char* ezStringBase<Derived>::FindWholeWord_NoCase(const char* szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER IsDelimiterCB, const char* szStartSearchAt /* = nullptr */) const
111 {
112  if (szStartSearchAt == nullptr)
113  szStartSearchAt = InternalGetData();
114 
115  EZ_ASSERT_DEV((szStartSearchAt >= InternalGetData()) && (szStartSearchAt <= InternalGetDataEnd()), "The given pointer to start searching at is not inside this strings valid range.");
116 
117  return ezStringUtils::FindWholeWord_NoCase(szStartSearchAt, szSearchFor, IsDelimiterCB, InternalGetDataEnd());
118 }
119 
120 template <typename Derived>
121 ezInt32 ezStringBase<Derived>::Compare(const char* pString2) const
122 {
123  return ezStringUtils::Compare(InternalGetData(), pString2, InternalGetDataEnd());
124 }
125 
126 template <typename Derived>
127 ezInt32 ezStringBase<Derived>::CompareN(const char* pString2, ezUInt32 uiCharsToCompare) const
128 {
129  return ezStringUtils::CompareN(InternalGetData(), pString2, uiCharsToCompare, InternalGetDataEnd());
130 }
131 
132 template <typename Derived>
133 ezInt32 ezStringBase<Derived>::Compare_NoCase(const char* pString2) const
134 {
135  return ezStringUtils::Compare_NoCase(InternalGetData(), pString2, InternalGetDataEnd());
136 }
137 
138 template <typename Derived>
139 ezInt32 ezStringBase<Derived>::CompareN_NoCase(const char* pString2, ezUInt32 uiCharsToCompare) const
140 {
141  return ezStringUtils::CompareN_NoCase(InternalGetData(), pString2, uiCharsToCompare, InternalGetDataEnd());
142 }
143 
144 template <typename Derived>
145 bool ezStringBase<Derived>::IsEqual(const char* pString2) const
146 {
147  return ezStringUtils::IsEqual(InternalGetData(), pString2, InternalGetDataEnd());
148 }
149 
150 template <typename Derived>
151 bool ezStringBase<Derived>::IsEqualN(const char* pString2, ezUInt32 uiCharsToCompare) const
152 {
153  return ezStringUtils::IsEqualN(InternalGetData(), pString2, uiCharsToCompare, InternalGetDataEnd());
154 }
155 
156 template <typename Derived>
157 bool ezStringBase<Derived>::IsEqual_NoCase(const char* pString2) const
158 {
159  return ezStringUtils::IsEqual_NoCase(InternalGetData(), pString2, InternalGetDataEnd());
160 }
161 
162 template <typename Derived>
163 bool ezStringBase<Derived>::IsEqualN_NoCase(const char* pString2, ezUInt32 uiCharsToCompare) const
164 {
165  return ezStringUtils::IsEqualN_NoCase(InternalGetData(), pString2, uiCharsToCompare, InternalGetDataEnd());
166 }
167 
168 template <typename Derived>
169 const char* ezStringBase<Derived>::ComputeCharacterPosition(ezUInt32 uiCharacterIndex) const
170 {
171  const char* pos = InternalGetData();
172  ezUnicodeUtils::MoveToNextUtf8(pos, uiCharacterIndex);
173  return pos;
174 }
175 
176 template <typename Derived>
178 {
179  return begin(*this);
180 }
181 
182 template <typename Derived>
184 {
185  return rbegin(*this);
186 }
187 
188 template <typename DerivedLhs, typename DerivedRhs>
189 EZ_FORCE_INLINE bool operator== (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
190 {
191  return ezStringUtils::IsEqual(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd());
192 }
193 
194 template <typename DerivedRhs>
195 EZ_FORCE_INLINE bool operator== (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
196 {
197  return rhs.IsEqual(lhs);
198 }
199 
200 template <typename DerivedLhs>
201 EZ_FORCE_INLINE bool operator== (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
202 {
203  return lhs.IsEqual(rhs);
204 }
205 
206 template <typename DerivedLhs, typename DerivedRhs>
207 EZ_FORCE_INLINE bool operator!= (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
208 {
209  return !ezStringUtils::IsEqual(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd());
210 }
211 
212 template <typename DerivedRhs>
213 EZ_FORCE_INLINE bool operator!= (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
214 {
215  return !rhs.IsEqual(lhs);
216 }
217 
218 template <typename DerivedLhs>
219 EZ_FORCE_INLINE bool operator!= (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
220 {
221  return !lhs.IsEqual(rhs);
222 }
223 
224 template <typename DerivedLhs, typename DerivedRhs>
225 EZ_FORCE_INLINE bool operator< (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
226 {
227  return ezStringUtils::Compare(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd()) < 0;
228 }
229 
230 template <typename DerivedRhs>
231 EZ_FORCE_INLINE bool operator< (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
232 {
233  return rhs.Compare(lhs) > 0;
234 }
235 
236 template <typename DerivedLhs>
237 EZ_FORCE_INLINE bool operator< (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
238 {
239  return lhs.Compare(rhs) < 0;
240 }
241 
242 template <typename DerivedLhs, typename DerivedRhs>
243 EZ_FORCE_INLINE bool operator> (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
244 {
245  return ezStringUtils::Compare(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd()) > 0;
246 }
247 
248 template <typename DerivedRhs>
249 EZ_FORCE_INLINE bool operator> (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
250 {
251  return rhs.Compare(lhs) < 0;
252 }
253 
254 template <typename DerivedLhs>
255 EZ_FORCE_INLINE bool operator> (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
256 {
257  return lhs.Compare(rhs) > 0;
258 }
259 
260 template <typename DerivedLhs, typename DerivedRhs>
261 EZ_FORCE_INLINE bool operator<= (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
262 {
263  return ezStringUtils::Compare(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd()) <= 0;
264 }
265 
266 template <typename DerivedRhs>
267 EZ_FORCE_INLINE bool operator<= (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
268 {
269  return rhs.Compare(lhs) >= 0;
270 }
271 
272 template <typename DerivedLhs>
273 EZ_FORCE_INLINE bool operator<= (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
274 {
275  return lhs.Compare(rhs) <= 0;
276 }
277 
278 template <typename DerivedLhs, typename DerivedRhs>
279 EZ_FORCE_INLINE bool operator>= (const ezStringBase<DerivedLhs>& lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
280 {
281  return ezStringUtils::Compare(lhs.InternalGetData(), rhs.InternalGetData(), lhs.InternalGetDataEnd(), rhs.InternalGetDataEnd()) >= 0;
282 }
283 
284 template <typename DerivedRhs>
285 EZ_FORCE_INLINE bool operator>= (const char* lhs, const ezStringBase<DerivedRhs>& rhs) // [tested]
286 {
287  return rhs.Compare(lhs) <= 0;
288 }
289 
290 template <typename DerivedLhs>
291 EZ_FORCE_INLINE bool operator>= (const ezStringBase<DerivedLhs>& lhs, const char* rhs) // [tested]
292 {
293  return lhs.Compare(rhs) >= 0;
294 }
295 
296