Subversion Repositories spk

Rev

Rev 213 | Rev 246 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
195 cycrow 1
 
2
#include "WStringList.h"
3
#include "spkdef.h"
4
 
5
namespace Utils {
6
	WStringList::WStringList()
7
	{
8
		_lList = new CList<WStringNode>();
9
	}
10
 
11
	WStringList::~WStringList()
12
	{
13
		delete _lList;
14
	}
15
 
16
	void WStringList::pushBack(const WString &str, const WString &data)
17
	{
18
		WStringNode *strNode = new WStringNode;
19
		strNode->str = str;
20
		strNode->data = data;
21
		_lList->push_back(strNode);
22
	}
23
 
24
	void WStringList::popFront()
25
	{
26
		if (!_lList->empty())
27
		{
28
			delete _lList->front();
29
			_lList->removeAt(0);
30
		}
31
	}
32
	void WStringList::popBack()
33
	{
34
		if (!_lList->empty())
35
		{
36
			delete _lList->back();
37
			_lList->pop_back();
38
		}
39
	}
40
	void WStringList::pushBack(const WString &str)
41
	{
213 cycrow 42
		pushBack(str, L"");
195 cycrow 43
	}
44
 
45
	void WStringList::pushFront(const WString &str, const WString &data)
46
	{
47
		WStringNode* strNode = new WStringNode;
48
		strNode->str = str;
49
		strNode->data = data;
50
		_lList->push_front(strNode);
51
	}
52
	void WStringList::pushFront(const WString &str)
53
	{
213 cycrow 54
		pushFront(str, L"");
195 cycrow 55
	}
56
 
57
	void WStringList::insertAt(int at, const WString& str, const WString& data)
58
	{
59
		WStringNode *strNode = new WStringNode;
60
		strNode->str = str;
61
		strNode->data = data;
62
		_lList->insertAt(at, strNode);
63
	}
64
	void WStringList::insertAt(int at, const WString& str)
65
	{
213 cycrow 66
		insertAt(at, str, L"");
195 cycrow 67
	}
68
 
69
	void WStringList::clear()
70
	{
71
		_lList->clear();
72
	}
73
 
74
	void WStringList::tokenise(const WString &str, const WString &token)
75
	{
76
		int max = 0;
77
		Utils::WString *strs = str.tokenise(token, &max);
78
		for ( int i = 0; i < max; i++ ) {
79
			this->pushBack(strs[i], Utils::WString::Null());
80
		}
81
 
82
		CLEANSPLIT(strs, max);
83
	}
84
 
85
	Utils::WString WStringList::firstString()
86
	{
87
		WStringNode *node = _lList->first();
88
		if ( node ) return node->str;
89
		return Utils::WString::Null();
90
	}
91
 
92
	Utils::WString WStringList::nextString()
93
	{
94
		WStringNode *node = _lList->next();
95
		if ( node ) return node->str;
96
		return Utils::WString::Null();
97
	}
98
 
99
	Utils::WStringNode *WStringList::first()
100
	{
101
		return _lList->first();
102
	}
103
 
104
	Utils::WStringNode *WStringList::next()
105
	{
106
		return _lList->next();
107
	}
108
 
109
	WStringListIterator WStringList::begin() const
110
	{
111
		return _lList->begin();
112
	}
113
 
114
	WStringListIterator WStringList::end() const
115
	{
116
		return _lList->end();
117
	}
118
 
119
	Utils::WString WStringList::front() const
120
	{
121
		auto front = _lList->front();
122
		if (front)
123
			return front->str;
124
		return Utils::WString::Null();
125
	}
126
 
127
	Utils::WString WStringList::back() const
128
	{
129
		auto front = _lList->back();
130
		if (front)
131
			return front->str;
132
		return Utils::WString::Null();
133
	}
134
 
135
	Utils::WStringNode *WStringList::get(int i) const
136
	{
137
		return _lList->get(i);
138
	}
139
 
140
	Utils::WString WStringList::findData(const Utils::WString &data, bool bIgnoreCase) const
141
	{
142
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
143
			if ((*itr)->data.Compare(data, !bIgnoreCase))
144
				return (*itr)->str;
145
		}
146
 
147
		return WString::Null();
148
	}
149
 
150
	Utils::WString WStringList::findString(const Utils::WString &str, bool bIgnoreCase) const
151
	{
152
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
153
			if ((*itr)->str.Compare(str, !bIgnoreCase))
154
				return (*itr)->data;
155
		}
156
 
157
		return WString::Null();
158
	}
159
 
160
	int WStringList::findStringAndData(const Utils::WString& str, const Utils::WString& data, bool bIgnoreCase) const
161
	{
162
		size_t pos = 0;
163
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++, pos++) {
164
			if ((*itr)->str.Compare(str, !bIgnoreCase))
165
			{
166
				if ((*itr)->data.Compare(data, !bIgnoreCase))
167
					return static_cast<int>(pos);
168
			}
169
		}
170
 
171
		return -1;
172
	}
173
 
174
	int WStringList::findPos(const Utils::WString& str, bool bIgnoreCase) const
175
	{
176
		size_t pos = 0;
177
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++, pos++) {
178
			if ((*itr)->str.Compare(str, !bIgnoreCase))
179
				return static_cast<int>(pos);
180
		}
181
 
182
		return -1;
183
	}
184
 
185
	bool WStringList::containsStringAndData(const Utils::WString& str, const Utils::WString& data, bool bIgnoreCase) const
186
	{
187
		size_t pos = 0;
188
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++, pos++) {
189
			if ((*itr)->str.Compare(str, !bIgnoreCase))
190
			{
191
				if ((*itr)->data.Compare(data, !bIgnoreCase))
192
					return true;
193
			}
194
		}
195
 
196
		return false;
197
	}
198
 
199
	bool WStringList::containsData(const Utils::WString &data, bool bIgnoreCase) const
200
	{
201
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
202
			if ((*itr)->data.Compare(data, !bIgnoreCase))
203
				return true;
204
		}
205
 
206
		return false;
207
	}
208
 
209
	bool WStringList::changeData(const Utils::WString &str, const Utils::WString &data, bool bIgnoreCase)
210
	{
211
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
212
			if ((*itr)->str.Compare(str, !bIgnoreCase))
213
			{
214
				(*itr)->data = data;
215
				return true;
216
			}
217
		}
218
 
219
		return false;
220
	}
221
 
222
	bool WStringList::contains(const Utils::WString &str, bool bIgnoreCase) const
223
	{
224
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
225
			if ((*itr)->str.Compare(str, !bIgnoreCase))
226
				return true;
227
		}
228
 
229
		return false;
230
	}
231
 
232
	void WStringList::removeAt(int at)
233
	{
234
		if (!_lList->empty())
235
		{
236
			auto var = _lList->get(at);
237
			if (var)
238
				delete var;
239
			_lList->removeAt(at);
240
		}
241
	}
242
 
243
	WStringListIterator WStringList::remove(WStringListIterator itr)
244
	{
245
		return _lList->remove(itr);
246
	}
247
	bool WStringList::remove(const Utils::WString &str, bool single)
248
	{
249
		bool removed = false;
250
 
251
		CList<Utils::WStringNode>::iterator itr = _lList->begin();
252
		while (itr != _lList->end())
253
		{
254
			Utils::WStringNode *node = *itr;
255
			if (node->str == str)
256
			{
257
				itr = _lList->remove(itr);
258
				if (single)
259
					break;
260
			}
261
			else
262
				++itr;
263
		}
264
 
265
 
266
		return removed;
267
	}
268
 
269
 
270
 
271
 
272
	size_t WStringList::size() const
273
	{
274
		return _lList->size();
275
	}
276
 
277
	bool WStringList::empty() const
278
	{
279
		return _lList->empty();
280
	}
281
 
282
	const Utils::WStringNode* WStringList::operator[](int num) const
283
	{
284
		return _lList->get(num);
285
	}
286
 
216 cycrow 287
	Utils::WStringNode* WStringList::operator[](int num)
288
	{
289
		return _lList->get(num);
290
	}
291
	const Utils::WStringNode* WStringList::operator[](const WString& str) const
292
	{
293
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
294
			if ((*itr)->str.Compare(str, true))
295
				return *itr;
296
		}
297
 
298
		return nullptr;
299
	}
300
	Utils::WStringNode* WStringList::operator[](const WString& str)
301
	{
302
		for (CList<WStringNode>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
303
			if ((*itr)->str.Compare(str, true))
304
				return *itr;
305
		}
306
 
307
		return nullptr;
308
	}
195 cycrow 309
}