ezEngine  Milestone 7
String_inl.h
1 #pragma once
2 
3 template<ezUInt16 Size>
5  m_Data(pAllocator)
6 {
7  Clear();
8 }
9 
10 template<ezUInt16 Size>
12  m_Data(pAllocator)
13 {
14  *this = rhs;
15 }
16 
17 template<ezUInt16 Size>
19  m_Data(pAllocator)
20 {
21  operator=(std::move(rhs));
22 }
23 
24 template<ezUInt16 Size>
26  m_Data(pAllocator)
27 {
28  *this = rhs;
29 }
30 
31 template<ezUInt16 Size>
33  m_Data(pAllocator)
34 {
35  *this = rhs;
36 }
37 
38 template<ezUInt16 Size>
40  m_Data(pAllocator)
41 {
42  *this = rhs;
43 }
44 
45 template<ezUInt16 Size>
47 {
48 }
49 
50 template<ezUInt16 Size>
52 {
53  return ezStringView(GetData(), GetData() + m_Data.GetCount() - 1);
54 }
55 
56 template<ezUInt16 Size>
58 {
59  m_Data.SetCount(1);
60  m_Data[0] = '\0';
61  m_uiCharacterCount = 0;
62 }
63 
64 template<ezUInt16 Size>
65 EZ_FORCE_INLINE const char* ezHybridStringBase<Size>::GetData() const
66 {
67  EZ_ASSERT_DEBUG(!m_Data.IsEmpty(), "ezHybridString has been corrupted, the array can never be empty.");
68 
69  return &m_Data[0];
70 }
71 
72 template<ezUInt16 Size>
73 EZ_FORCE_INLINE ezUInt32 ezHybridStringBase<Size>::GetElementCount() const
74 {
75  return m_Data.GetCount() - 1;
76 }
77 
78 template<ezUInt16 Size>
79 EZ_FORCE_INLINE ezUInt32 ezHybridStringBase<Size>::GetCharacterCount() const
80 {
81  return m_uiCharacterCount;
82 }
83 
84 template<ezUInt16 Size>
85 void ezHybridStringBase<Size>::operator=(const char* szString)
86 {
87  ezUInt32 uiElementCount = 0;
88  ezStringUtils::GetCharacterAndElementCount(szString, m_uiCharacterCount, uiElementCount);
89  m_Data.SetCount(uiElementCount + 1);
90  ezStringUtils::Copy(&m_Data[0], uiElementCount + 1, szString);
91 }
92 
93 template<ezUInt16 Size>
95 {
96  if (this == &rhs)
97  return;
98 
99  m_uiCharacterCount = rhs.m_uiCharacterCount;
100  m_Data = rhs.m_Data;
101 }
102 
103 template<ezUInt16 Size>
105 {
106  if (this == &rhs)
107  return;
108 
109  m_uiCharacterCount = rhs.m_uiCharacterCount;
110  m_Data = std::move(rhs.m_Data);
111 }
112 
113 template<ezUInt16 Size>
114 void ezHybridStringBase<Size>::operator=(const wchar_t* szString)
115 {
116  ezStringUtf8 sConversion(szString, m_Data.GetAllocator());
117  *this = sConversion.GetData();
118 }
119 
120 template<ezUInt16 Size>
122 {
123  m_Data.SetCount(rhs.GetElementCount() + 1);
124  ezStringUtils::Copy(&m_Data[0], m_Data.GetCount() + 1, rhs.GetData(), rhs.GetEndPosition());
125  m_uiCharacterCount = ezStringUtils::GetCharacterCount(GetData());
126 }
127 
128 template<ezUInt16 Size>
129 ezStringView ezHybridStringBase<Size>::GetSubString(ezUInt32 uiFirstCharacter, ezUInt32 uiNumCharacters) const
130 {
131  EZ_ASSERT_DEV(uiFirstCharacter < m_uiCharacterCount, "The string only has %i characters, cannot start a sub-string at character %i.", m_uiCharacterCount, uiFirstCharacter);
132  EZ_ASSERT_DEV(uiFirstCharacter + uiNumCharacters <= m_uiCharacterCount, "The string only has %i characters, cannot get a sub-string up to character %i.", m_uiCharacterCount, uiFirstCharacter + uiNumCharacters);
133 
134  const char* szStart = GetData();
135  ezUnicodeUtils::MoveToNextUtf8(szStart, uiFirstCharacter);
136 
137  const char* szEnd = szStart;
138  ezUnicodeUtils::MoveToNextUtf8(szEnd, uiNumCharacters);
139 
140  return ezStringView(szStart, szEnd);
141 }
142 
143 template<ezUInt16 Size>
144 ezStringView ezHybridStringBase<Size>::GetFirst(ezUInt32 uiNumCharacters) const
145 {
146  return GetSubString(0, uiNumCharacters);
147 }
148 
149 template<ezUInt16 Size>
150 ezStringView ezHybridStringBase<Size>::GetLast(ezUInt32 uiNumCharacters) const
151 {
152  EZ_ASSERT_DEV(uiNumCharacters < m_uiCharacterCount, "The string only contains %i characters, cannot return the last %i characters.", m_uiCharacterCount, uiNumCharacters);
153  return GetSubString(m_uiCharacterCount - uiNumCharacters, uiNumCharacters);
154 }
155 
156 
157 template <ezUInt16 Size, typename A>
158 EZ_FORCE_INLINE ezHybridString<Size, A>::ezHybridString() :
159  ezHybridStringBase<Size>(A::GetAllocator())
160 {
161 }
162 
163 template <ezUInt16 Size, typename A>
164 EZ_FORCE_INLINE ezHybridString<Size, A>::ezHybridString(ezAllocatorBase* pAllocator) :
165  ezHybridStringBase<Size>(pAllocator)
166 {
167 }
168 
169 template <ezUInt16 Size, typename A>
171  ezHybridStringBase<Size>(other, A::GetAllocator())
172 {
173 }
174 
175 template <ezUInt16 Size, typename A>
177  ezHybridStringBase<Size>(other, A::GetAllocator())
178 {
179 }
180 
181 template <ezUInt16 Size, typename A>
183  ezHybridStringBase<Size>(std::move(other), A::GetAllocator())
184 {
185 }
186 
187 template <ezUInt16 Size, typename A>
189  ezHybridStringBase<Size>(std::move(other), A::GetAllocator())
190 {
191 }
192 
193 template <ezUInt16 Size, typename A>
194 EZ_FORCE_INLINE ezHybridString<Size, A>::ezHybridString(const char* rhs) :
195  ezHybridStringBase<Size>(rhs, A::GetAllocator())
196 {
197 }
198 
199 template <ezUInt16 Size, typename A>
200 EZ_FORCE_INLINE ezHybridString<Size, A>::ezHybridString(const wchar_t* rhs) :
201  ezHybridStringBase<Size>(rhs, A::GetAllocator())
202 {
203 }
204 
205 template <ezUInt16 Size, typename A>
206 EZ_FORCE_INLINE ezHybridString<Size, A>::ezHybridString(const ezStringView& rhs) :
207  ezHybridStringBase<Size>(rhs, A::GetAllocator())
208 {
209 }
210 
211 template <ezUInt16 Size, typename A>
212 EZ_FORCE_INLINE void ezHybridString<Size, A>::operator=(const ezHybridString<Size, A>& rhs)
213 {
215 }
216 
217 template <ezUInt16 Size, typename A>
218 EZ_FORCE_INLINE void ezHybridString<Size, A>::operator=(const ezHybridStringBase<Size>& rhs)
219 {
221 }
222 
223 template <ezUInt16 Size, typename A>
225 {
226  ezHybridStringBase<Size>::operator=(std::move(rhs));
227 }
228 
229 template <ezUInt16 Size, typename A>
231 {
232  ezHybridStringBase<Size>::operator=(std::move(rhs));
233 }
234 
235 template <ezUInt16 Size, typename A>
236 EZ_FORCE_INLINE void ezHybridString<Size, A>::operator=(const char* rhs)
237 {
239 }
240 
241 template <ezUInt16 Size, typename A>
242 EZ_FORCE_INLINE void ezHybridString<Size, A>::operator=(const wchar_t* rhs)
243 {
245 }
246 
247 template <ezUInt16 Size, typename A>
248 EZ_FORCE_INLINE void ezHybridString<Size, A>::operator=(const ezStringView& rhs)
249 {
251 }
252 
253 #include <Foundation/Strings/Implementation/AllStrings_inl.h>
254