acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_want_to_remove_str_wstring.h
1#pragma once
2
3
4#include "acme/prototype/prototype/memory_c.h"
5
6
7
8CLASS_DECL_ACME wstring operator + (const wstring & wstr1, const wstring & wstr2);
9CLASS_DECL_ACME wstring operator + (const wstring & str, const wide_character * psz);
10CLASS_DECL_ACME wstring operator + (const wide_character * psz, const wstring & str);
11
12
13CLASS_DECL_ACME wstring gen_utf8_to_16(const ::scoped_string & scopedstr);
14
15
16//class CLASS_DECL_ACME wstring_data
17//{
18//protected:
19//
20//
21// friend class wstring;
22// friend class wstring_adaptor;
23//
24//
25// static wide_character * get_nil();
26//
27//
28//public:
29//
30//
31// ::collection::count m_iAllocation; // in chars "with nullptr characters"
32// ::collection::count m_iLength; // in chars without nullptr character
33// unichar m_wchFirst;
34//
35//
36// // nil constructor
37// inline wstring_data()
38// {
39// m_iAllocation = 0;
40// m_iLength = 0;
41// m_wchFirst = L'\0';
42// }
43//
44// inline wstring_data * clone() const
45// {
46// wstring_data * pdata = (wstring_data *)aligned_memory_allocate(((m_iAllocation + 1) * sizeof(unichar)) + sizeof(count) + sizeof(count) + sizeof(unichar));
47// memory_copy(pdata, this, ((m_iAllocation + 1) * sizeof(unichar)) + sizeof(count) + sizeof(count) + sizeof(unichar));
48// return pdata;
49// }
50//
51//
52// inline static wide_character * alloc(::collection::count iCount)
53// {
54//
55// wstring_data * pdata = (wstring_data *) aligned_memory_allocate(((iCount + 1) * sizeof(unichar)) + sizeof(count) + sizeof(count) + sizeof(unichar));
56// pdata->m_iAllocation = iCount;
57// pdata->m_iLength = 0;
58// pdata->m_wchFirst = L'\0';
59// return &pdata->m_wchFirst;
60//
61// }
62//
63// inline static void _free(wide_character * pwsz)
64// {
65// if(pwsz == nullptr)
66// return;
67// if (pwsz == get_nil())
68// return;
69// wstring_data * pdata = (wstring_data *) (((::u8 *) pwsz) - sizeof(count) - sizeof(count));
70// if(pdata->m_iAllocation <= 0)
71// return;
72// ::system()->m_pheapmanagement->memory(::heap::e_memory_main)->free(pdata);
73//
74// }
75//
76//
77// inline operator const wide_character * () const { return &m_wchFirst; }
78// inline operator wide_character * () { return &m_wchFirst; }
79//
80//
81//};
82
83
84class wstring_manager;
85
86#ifdef WINDOWS
87#define unilen wcslen
88#else
89#define unilen wide_length
90#endif
91
92class CLASS_DECL_ACME wstring :
93 public wstring
94{
95public:
96
97 static const ::i32 npos;
98 typedef wstring_manager manager;
99 typedef unichar value_type;
100 typedef wstring_data data_type;
101
102
103
104//
105// friend class wstring_adaptor;
106//
107// // it is and should be really a pointer to the m_pwsz of a wstring_data alloced in heap
108// // better always use wstring_data::alloc and wstring_data::free
109// wide_character * m_pwsz;
110//
111// inline wstring_data * get_data()
112// {
113// return (wstring_data *)(((::u8 *) m_pwsz) - sizeof(count) - sizeof(count));
114// }
115//
116// inline const wstring_data * get_data() const
117// {
118// return (wstring_data *)(((::u8 *) m_pwsz) - sizeof(count) - sizeof(count));
119// }
120//
121//public:
122
123 wstring();
124 wstring(for_moving) {};
125 wstring(manager * pstringmanager);
126 void construct(manager * pstringmanager = nullptr);
127 wstring(const wstring & strSrc,manager * pstringmanager = nullptr);
128 wstring(const ::scoped_string & scopedstrSrc,manager * pstringmanager = nullptr);
129 wstring(const ::u8 * pszSrc,manager * pstringmanager = nullptr);
130 wstring(const ::u8 * pszSrc, character_count nLength, manager * pstringmanager = nullptr);
131 wstring(const wide_character * pchSrc, manager * pstringmanager = nullptr);
132 wstring(const wide_character * pchSrc, character_count nLength,manager * pstringmanager = nullptr);
133 inline wstring(const wstring_data * pdata,manager * pstringmanager = nullptr)
134 {
135 __UNREFERENCED_PARAMETER(pstringmanager);
136 m_pwsz = (wide_character * ) &pdata->m_wchFirst;
137 }
138 ~wstring();
139
140
141 inline void attach(wstring_data * pdata)
142 {
143 if(m_pwsz != nullptr)
144 {
145 wstring_data::_free(m_pwsz);
146 }
147 m_pwsz = &pdata->m_wchFirst;
148 }
149
150 inline wstring_data * detach()
151 {
152 wstring_data * pdata = get_data();
153 m_pwsz = wstring_data::get_nil();
154 return pdata;
155 }
156
157
158 void reserve(character_count n) { __UNREFERENCED_PARAMETER(n); } // wstring does not prereserve
159
160 wstring & operator = (const wstring & wstr);
161 wstring & operator = (const wide_character * pwsz);
162 wstring & operator = (const ::scoped_string & scopedstr);
163
164
165 inline operator const wide_character * () const { return get_data()->m_iAllocation <= 0 ? wstring_data::get_nil() : m_pwsz; }
166 inline operator const wide_character * () { return get_data()->m_iAllocation <= 0 ? wstring_data::get_nil() : m_pwsz; }
167
168 inline operator wide_character * () const { return get_data()->m_iAllocation <= 0 ? wstring_data::get_nil() : m_pwsz; }
169 inline operator wide_character * () { return get_data()->m_iAllocation <= 0 ? wstring_data::get_nil() : m_pwsz; }
170
171
172 inline const wide_character * c_str() const { return this->operator const wide_character * (); }
173
174#if defined(UNIVERSAL_WINDOWS) && defined(__cplusplus_winrt)
175 inline operator String ^ () const { return ref aaa_primitive_new String(operator const wide_character * ()); }
176 inline operator String ^ () { return ref aaa_primitive_new String(operator const wide_character * ()); }
177#endif
178
179 inline wstring & operator += (unichar wch) { append(wch); return *this; }
180 inline wstring & operator += (const wide_character * pwsz) { append(pwsz); return *this; }
181
182
183
184 inline unichar operator [] (::collection::index iIndex) const
185 {
186 return m_pwsz[iIndex];
187 }
188
189 inline unichar & operator [] (::collection::index iIndex)
190 {
191 return m_pwsz[iIndex];
192 }
193
194 wide_character * alloc(::collection::count iCount);
195
196 inline ::collection::count get_length() const
197 {
198 return get_data()->m_iLength;
199 }
200
201 inline ::collection::count length() const
202 {
203 return get_data()->m_iLength;
204 }
205
206 inline ::collection::count size() const
207 {
208 return get_data()->m_iLength;
209 }
210
211 inline ::collection::count storage_size() const
212 {
213 return get_data()->m_iAllocation;
214 }
215
216 inline ::collection::count allocation_size() const
217 {
218 return get_data()->m_iAllocation;
219 }
220
221 inline ::collection::count get_storage_size() const
222 {
223 return get_data()->m_iAllocation;
224 }
225
226 inline ::collection::count get_allocation_size() const
227 {
228 return get_data()->m_iAllocation;
229 }
230
231 inline bool operator == (const wide_character * pwsz) const
232 {
233 return Compare(pwsz) == 0;
234 }
235
236 inline bool operator == (const wstring & wstr) const;
237
238 inline ::i32 Compare(const wide_character * psz) const
239 {
240 return wide_compare(m_pwsz, psz);
241 }
242
243 inline ::i32 Compare(const wstring &str) const
244 {
245 return wide_compare(m_pwsz, str);
246 }
247
248 inline ::i32 CompareNoCase(const wide_character * psz) const
249 {
250 return wide_compare_case_insensitive(m_pwsz, psz);
251 }
252
253 inline ::i32 CompareNoCase(const wstring &str) const
254 {
255 return wide_compare_case_insensitive(m_pwsz, str);
256 }
257
258
259 inline bool is_empty() const
260 {
261 return get_data()->m_iLength <= 0 || *m_pwsz == L'\0';
262 }
263
264
265 inline void set_length(::collection::count iLength)
266 {
267
268 if(iLength <= get_data()->m_iAllocation)
269 {
270 get_data()->m_iLength = iLength;
271 }
272 else
273 {
274 get_data()->m_iLength = 0;
275 }
276 m_pwsz[iLength] = L'\0';
277 }
278
279 inline void release_buffer()
280 {
281
282 set_length(wide_length(m_pwsz));
283
284 }
285
286
287 inline static wstring empty_string()
288 {
289 unichar push[]= {0};
290 return push;
291 }
292
293 inline wstring & append(unichar wch)
294 {
295
296 unichar wsz[2];
297
298 wsz[0] = wch;
299
300 wsz[1] = L'\0';
301
302 return *this = (*this + wsz);
303
304 }
305
306 inline wstring & append(unichar wch, ::collection::count c)
307 {
308
309 while(c > 0)
310 {
311
312 append(wch);
313
314 c--;
315
316 }
317
318 return *this;
319
320 }
321
322 inline wstring & append(const wide_character * pwsz) { assign(*this + pwsz); return *this; }
323
324 wstring substr(::collection::index iStart, ::collection::count c = -1);
325 wstring & replace(::collection::index iStart,::collection::count c, const wide_character * psz);
326
327
328 wstring & operator = (const ::scoped_string & scopedstr);
329
330 void assign(const wide_character * pwsz);
331 void assign(const ::scoped_string & scopedstr);
332
333
334 character_count find(unichar ch,character_count start = 0,character_count count = -1) const RELEASENOTHROW;
335 character_count find(const wide_character * pszSub,character_count start = 0,character_count count = -1,const wide_character * * pszTail = nullptr) const RELEASENOTHROW;
336
337 bool empty() const { return is_empty(); }
338
339
340};
341
342
343
Definition cfref.h:37
Definition aaa_want_to_remove_str_wstring.h:94