Subversion Repositories spk

Rev

Rev 160 | Rev 170 | 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
 
166
	bool CStringList::containsStringAndData(const Utils::String& str, const Utils::String& data, 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
			{
172
				if ((*itr)->data.Compare(data, !bIgnoreCase))
173
					return true;
174
			}
175
		}
176
 
177
		return false;
178
	}
179
 
121 cycrow 180
	bool CStringList::containsData(const Utils::String &data, bool bIgnoreCase) const
181
	{
182
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
183
			if ((*itr)->data.Compare(data, !bIgnoreCase))
184
				return true;
185
		}
186
 
187
		return false;
188
	}
189
 
124 cycrow 190
	bool CStringList::changeData(const Utils::String &str, const Utils::String &data, bool bIgnoreCase)
191
	{
192
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
193
			if ((*itr)->str.Compare(str, !bIgnoreCase))
194
			{
195
				(*itr)->data = data;
196
				return true;
197
			}
198
		}
199
 
200
		return false;
201
	}
202
 
121 cycrow 203
	bool CStringList::contains(const Utils::String &str, bool bIgnoreCase) const
204
	{
205
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
206
			if ((*itr)->str.Compare(str, !bIgnoreCase))
207
				return true;
208
		}
209
 
210
		return false;
211
	}
212
 
213
	void CStringList::removeAt(int at)
214
	{
215
		_lList->removeAt(at);
216
	}
217
	bool CStringList::remove(const Utils::String &str, bool single)
218
	{
219
		bool removed = false;
220
 
221
		CList<Utils::SStringList>::iterator itr = _lList->begin();
222
		while (itr != _lList->end())
223
		{
224
			Utils::SStringList *node = *itr;
225
			if (node->str == str)
226
			{
227
				itr = _lList->remove(itr);
228
				if (single)
229
					break;
230
			}
231
			else
232
				++itr;
233
		}
234
 
235
 
236
		return removed;
237
	}
238
 
239
 
240
 
241
 
112 cycrow 242
	size_t CStringList::size() const
243
	{
244
		return _lList->size();
245
	}
246
 
247
	bool CStringList::empty() const
248
	{
249
		return _lList->empty();
250
	}
165 cycrow 251
 
252
	const Utils::SStringList* CStringList::operator[](int num) const
253
	{
254
		return _lList->get(num);
255
	}
256
 
8 cycrow 257
}