Subversion Repositories spk

Rev

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