Subversion Repositories spk

Rev

Rev 179 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 cycrow 1
 
2
#include "StringList.h"
98 cycrow 3
#include "spkdef.h"
8 cycrow 4
 
5
namespace Utils {
112 cycrow 6
	CStringList::CStringList()
7
	{
8
		_lList = new CList<SStringList>();
9
	}
10
 
11
	CStringList::~CStringList()
12
	{
13
		delete _lList;
14
	}
15
 
196 cycrow 16
	void CStringList::pushBack(const SString &str, const SString &data)
8 cycrow 17
	{
18
		SStringList *strNode = new SStringList;
19
		strNode->str = str;
20
		strNode->data = data;
112 cycrow 21
		_lList->push_back(strNode);
8 cycrow 22
	}
160 cycrow 23
 
179 cycrow 24
	void CStringList::popFront()
25
	{
26
		if (!_lList->empty())
27
		{
28
			delete _lList->front();
29
			_lList->removeAt(0);
30
		}
31
	}
160 cycrow 32
	void CStringList::popBack()
33
	{
34
		if (!_lList->empty())
35
		{
36
			delete _lList->back();
37
			_lList->pop_back();
38
		}
39
	}
196 cycrow 40
	void CStringList::pushBack(const SString &str)
111 cycrow 41
	{
42
		pushBack(str, "");
43
	}
9 cycrow 44
 
196 cycrow 45
	void CStringList::pushFront(const SString &str, const SString &data)
121 cycrow 46
	{
47
		SStringList *strNode = new SStringList;
48
		strNode->str = str;
49
		strNode->data = data;
50
		_lList->push_front(strNode);
51
	}
196 cycrow 52
	void CStringList::pushFront(const SString &str)
121 cycrow 53
	{
54
		pushFront(str, "");
55
	}
56
 
196 cycrow 57
	void CStringList::insertAt(int at, const SString& str, const SString& data)
160 cycrow 58
	{
59
		SStringList* strNode = new SStringList;
60
		strNode->str = str;
61
		strNode->data = data;
62
		_lList->insertAt(at, strNode);
63
	}
196 cycrow 64
	void CStringList::insertAt(int at, const SString& str)
160 cycrow 65
	{
66
		insertAt(at, str, "");
67
	}
68
 
9 cycrow 69
	void CStringList::clear()
70
	{
112 cycrow 71
		_lList->clear();
9 cycrow 72
	}
98 cycrow 73
 
196 cycrow 74
	void CStringList::tokenise(const SString &str, const SString &token)
98 cycrow 75
	{
76
		int max = 0;
196 cycrow 77
		Utils::SString *strs = str.tokenise(token, &max);
98 cycrow 78
		for ( int i = 0; i < max; i++ ) {
196 cycrow 79
			this->pushBack(strs[i], Utils::SString::Null());
98 cycrow 80
		}
81
 
82
		CLEANSPLIT(strs, max);
83
	}
84
 
196 cycrow 85
	Utils::SString CStringList::firstString()
98 cycrow 86
	{
112 cycrow 87
		SStringList *node = _lList->first();
98 cycrow 88
		if ( node ) return node->str;
196 cycrow 89
		return Utils::SString::Null();
98 cycrow 90
	}
91
 
196 cycrow 92
	Utils::SString CStringList::nextString()
98 cycrow 93
	{
112 cycrow 94
		SStringList *node = _lList->next();
98 cycrow 95
		if ( node ) return node->str;
196 cycrow 96
		return Utils::SString::Null();
98 cycrow 97
	}
101 cycrow 98
 
112 cycrow 99
	Utils::SStringList *CStringList::first()
100
	{
101
		return _lList->first();
102
	}
103
 
104
	Utils::SStringList *CStringList::next()
105
	{
106
		return _lList->next();
107
	}
108
 
160 cycrow 109
	CStringListIterator CStringList::begin() const
112 cycrow 110
	{
111
		return _lList->begin();
112
	}
113
 
160 cycrow 114
	CStringListIterator CStringList::end() const
112 cycrow 115
	{
116
		return _lList->end();
117
	}
118
 
196 cycrow 119
	Utils::SString CStringList::front() const
160 cycrow 120
	{
121
		auto front = _lList->front();
122
		if (front)
123
			return front->str;
196 cycrow 124
		return Utils::SString::Null();
160 cycrow 125
	}
126
 
196 cycrow 127
	Utils::SString CStringList::back() const
160 cycrow 128
	{
129
		auto front = _lList->back();
130
		if (front)
131
			return front->str;
196 cycrow 132
		return Utils::SString::Null();
160 cycrow 133
	}
134
 
165 cycrow 135
	Utils::SStringList *CStringList::get(int i) const
116 cycrow 136
	{
137
		return _lList->get(i);
138
	}
139
 
196 cycrow 140
	Utils::SString CStringList::findData(const Utils::SString &data, bool bIgnoreCase) const
101 cycrow 141
	{
121 cycrow 142
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
143
			if ((*itr)->data.Compare(data, !bIgnoreCase))
112 cycrow 144
				return (*itr)->str;
101 cycrow 145
		}
146
 
196 cycrow 147
		return SString::Null();
101 cycrow 148
	}
149
 
196 cycrow 150
	Utils::SString CStringList::findString(const Utils::SString &str, bool bIgnoreCase) const
101 cycrow 151
	{
121 cycrow 152
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
153
			if ((*itr)->str.Compare(str, !bIgnoreCase))
112 cycrow 154
				return (*itr)->data;
101 cycrow 155
		}
156
 
196 cycrow 157
		return SString::Null();
101 cycrow 158
	}
8 cycrow 159
 
196 cycrow 160
	int CStringList::findStringAndData(const Utils::SString& str, const Utils::SString& data, bool bIgnoreCase) const
160 cycrow 161
	{
162
		size_t pos = 0;
163
		for (CList<SStringList>::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
 
196 cycrow 174
	int CStringList::findPos(const Utils::SString& str, bool bIgnoreCase) const
170 cycrow 175
	{
176
		size_t pos = 0;
177
		for (CList<SStringList>::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
 
196 cycrow 185
	bool CStringList::containsStringAndData(const Utils::SString& str, const Utils::SString& data, bool bIgnoreCase) const
160 cycrow 186
	{
187
		size_t pos = 0;
188
		for (CList<SStringList>::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
 
196 cycrow 199
	bool CStringList::containsData(const Utils::SString &data, bool bIgnoreCase) const
121 cycrow 200
	{
201
		for (CList<SStringList>::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
 
196 cycrow 209
	bool CStringList::changeData(const Utils::SString &str, const Utils::SString &data, bool bIgnoreCase)
124 cycrow 210
	{
211
		for (CList<SStringList>::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
 
196 cycrow 222
	bool CStringList::contains(const Utils::SString &str, bool bIgnoreCase) const
121 cycrow 223
	{
224
		for (CList<SStringList>::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 CStringList::removeAt(int at)
233
	{
179 cycrow 234
		if (!_lList->empty())
235
		{
236
			auto var = _lList->get(at);
237
			if (var)
238
				delete var;
239
			_lList->removeAt(at);
240
		}
121 cycrow 241
	}
170 cycrow 242
 
243
	CStringListIterator CStringList::remove(CStringListIterator itr)
244
	{
245
		return _lList->remove(itr);
246
	}
196 cycrow 247
	bool CStringList::remove(const Utils::SString &str, bool single)
121 cycrow 248
	{
249
		bool removed = false;
250
 
251
		CList<Utils::SStringList>::iterator itr = _lList->begin();
252
		while (itr != _lList->end())
253
		{
254
			Utils::SStringList *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
 
112 cycrow 272
	size_t CStringList::size() const
273
	{
274
		return _lList->size();
275
	}
276
 
277
	bool CStringList::empty() const
278
	{
279
		return _lList->empty();
280
	}
165 cycrow 281
 
282
	const Utils::SStringList* CStringList::operator[](int num) const
283
	{
284
		return _lList->get(num);
285
	}
286
 
8 cycrow 287
}