Subversion Repositories spk

Rev

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