acme
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages Concepts
string_iterable.h
1#pragma once
2
3
4#include "collection_iterable.h"
5
6
7namespace str
8{
9
10 namespace iter
11 {
12
13
14
15 } // namespace iter
16
17
18} // namespace str
19
20template < typename ITERABLE >
22 public ITERABLE
23{
24public:
25
26 typedef typename ITERABLE::iterator iterator;
27 typedef typename ITERABLE Iterable;
28 typedef typename ITERABLE::iterator iterator;
29 typedef typename Iterable::BASE_TYPE Type;
30 typedef iterable Container;
31
32 iterator add(const ::scoped_string & scopedstr);
33
34 iterator add(const unichar * pwsz);
35
36 iterator add(char ch);
37
38 iterator add(unichar wch);
39
40 iterator add(const ::payload & payload);
41
42 iterator add(const property & prop);
43
44 iterator add(const atom & atom);
45
46 iterator add(const Type & newElement);
47
48 bool erase_empty()
49 {
50
51 return ::iter::erase_empty(*this);
52
53 }
54
55 Container & trim_right()
56 {
57
58 return ::iter::trim_right(*this);
59
60 }
61
62 Container & trim_left()
63 {
64
65 return ::iter::trim_left(*this);
66
67 }
68
69
70 Container & trim()
71 {
72
73 return ::iter::trim(*this);
74
75 }
76
77
78};
79
80
81template < typename ITERABLE >
82typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(const ::scoped_string & scopedstr)
83{
84 ::collection::index nIndex = this->m_nSize;
85 set_at_grow(nIndex, psz);
86 return m_pData + nIndex;
87}
88
89
90template < typename ITERABLE >
91typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(const unichar * pwsz)
92{
93 ::collection::index nIndex = this->m_nSize;
94 set_at_grow(nIndex, (Type) unicode_to_utf8(pwsz));
95 return m_pData + nIndex;
96}
97
98
99
100template < typename ITERABLE >
101typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(char ch)
102{
103 if (ch == '\0')
104 return add("");
105 else
106 {
107 char str[16];
108 str[0] = ch;
109 str[1] = '\0';
110 return add(str);
111 }
112}
113
114
115template < typename ITERABLE >
116typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(unichar wch)
117{
118 if (wch == L'\0')
119 return add("");
120 else
121 {
122 unichar wstr[16];
123 wstr[0] = wch;
124 wstr[1] = L'\0';
125 return add(wstr);
126 }
127}
128
129
130template < typename ITERABLE >
131typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(const Type & newElement)
132{
133
134 ::collection::index nIndex = this->m_nSize;
135
136 set_at_grow(nIndex, newElement);
137
138 return m_pData + nIndex;
139
140}
141
142
143//template < typename ITERABLE >
144//void string_iterable < ITERABLE >::add(const Type & newElement)
145//{
146// index nIndex = this->m_nSize;
147// set_at_grow(nIndex, newElement);
148//}
149
150
151
152
153template < typename ITERABLE >
154typename string_iterable < ITERABLE >::iterator string_iterable < ITERABLE >::add(const atom & atom)
155{
156 if (atom.is_null())
157 {
158
159 return end();
160
161 }
162 else
163 {
164 add(atom);
165 }
166}
167
168
169
170
172//void string_iterable < ITERABLE >::erase_all()
173//{
174// set_size(0);
175//}
176//
178//void string_iterable < ITERABLE >::clear()
179//{
180// set_size(0);
181//}
182
183
184
185
186template < typename ITERABLE >
187typename ITERABLE::iterator string_iterable < ITERABLE >::add(const ::payload & payload)
188{
189 if (payload.is_empty())
190 {
191 return end();
192 }
193 else if (payload.get_type() == ::e_type_string_array)
194 {
195 ::acme::array::add(*this, payload.stra());
196 }
197 else if (payload.cast < string_array_base < Type > >() != nullptr)
198 {
199 ::acme::array::add(*this, *payload.cast < string_array_base < Type > >());
200 }
201 else if (payload.get_type() == ::type_vara)
202 {
203 for (int i = 0; i < payload.payloada().get_count(); i++)
204 {
205 add((Type) payload.payloada()[i].get_string());
206 }
207 }
208 else if (payload.get_type() == ::e_type_int_array)
209 {
210 for (int i = 0; i < payload.inta().get_count(); i++)
211 {
212 add((Type) as_string(payload.inta()[i]));
213 }
214 }
215 else if (payload.get_type() == ::e_type_property_set)
216 {
217 for (auto assoc : payload.propset())
218 {
219 add((Type) assoc.get_string());
220 }
221 }
222 else
223 {
224 add((Type) payload.get_string());
225 }
226
227 return upper_bound();
228
229}
230
231
232
233
234template < typename ITERABLE >
235typename ITERABLE::iterator string_iterable < ITERABLE >::add(const property & prop)
236{
237
238 return add(prop.get_value());
239
240}
Definition atom.h:233
Definition iterable.h:4040
Definition payload.h:53
Definition property.h:81
Definition string_iterable.h:23