Subversion Repositories spk

Rev

Rev 121 | Rev 160 | 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
	}
111 cycrow 23
	void CStringList::pushBack(const String &str)
24
	{
25
		pushBack(str, "");
26
	}
9 cycrow 27
 
121 cycrow 28
	void CStringList::pushFront(const String &str, const String &data)
29
	{
30
		SStringList *strNode = new SStringList;
31
		strNode->str = str;
32
		strNode->data = data;
33
		_lList->push_front(strNode);
34
	}
35
	void CStringList::pushFront(const String &str)
36
	{
37
		pushFront(str, "");
38
	}
39
 
9 cycrow 40
	void CStringList::clear()
41
	{
112 cycrow 42
		_lList->clear();
9 cycrow 43
	}
98 cycrow 44
 
45
	void CStringList::tokenise(const String &str, const String &token)
46
	{
47
		int max = 0;
48
		Utils::String *strs = str.tokenise(token, &max);
49
		for ( int i = 0; i < max; i++ ) {
50
			this->pushBack(strs[i], Utils::String::Null());
51
		}
52
 
53
		CLEANSPLIT(strs, max);
54
	}
55
 
56
	Utils::String CStringList::firstString()
57
	{
112 cycrow 58
		SStringList *node = _lList->first();
98 cycrow 59
		if ( node ) return node->str;
60
		return Utils::String::Null();
61
	}
62
 
63
	Utils::String CStringList::nextString()
64
	{
112 cycrow 65
		SStringList *node = _lList->next();
98 cycrow 66
		if ( node ) return node->str;
67
		return Utils::String::Null();
68
	}
101 cycrow 69
 
112 cycrow 70
	Utils::SStringList *CStringList::first()
71
	{
72
		return _lList->first();
73
	}
74
 
75
	Utils::SStringList *CStringList::next()
76
	{
77
		return _lList->next();
78
	}
79
 
80
	CStringListIterator CStringList::begin()
81
	{
82
		return _lList->begin();
83
	}
84
 
85
	CStringListIterator CStringList::end()
86
	{
87
		return _lList->end();
88
	}
89
 
116 cycrow 90
	Utils::SStringList *CStringList::get(int i)
91
	{
92
		return _lList->get(i);
93
	}
94
 
101 cycrow 95
	Utils::String CStringList::findData(const Utils::String &data, bool bIgnoreCase) const
96
	{
121 cycrow 97
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
98
			if ((*itr)->data.Compare(data, !bIgnoreCase))
112 cycrow 99
				return (*itr)->str;
101 cycrow 100
		}
101
 
102
		return String::Null();
103
	}
104
 
105
	Utils::String CStringList::findString(const Utils::String &str, bool bIgnoreCase) const
106
	{
121 cycrow 107
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
108
			if ((*itr)->str.Compare(str, !bIgnoreCase))
112 cycrow 109
				return (*itr)->data;
101 cycrow 110
		}
111
 
112
		return String::Null();
113
	}
8 cycrow 114
 
121 cycrow 115
	bool CStringList::containsData(const Utils::String &data, bool bIgnoreCase) const
116
	{
117
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
118
			if ((*itr)->data.Compare(data, !bIgnoreCase))
119
				return true;
120
		}
121
 
122
		return false;
123
	}
124
 
124 cycrow 125
	bool CStringList::changeData(const Utils::String &str, const Utils::String &data, bool bIgnoreCase)
126
	{
127
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
128
			if ((*itr)->str.Compare(str, !bIgnoreCase))
129
			{
130
				(*itr)->data = data;
131
				return true;
132
			}
133
		}
134
 
135
		return false;
136
	}
137
 
121 cycrow 138
	bool CStringList::contains(const Utils::String &str, bool bIgnoreCase) const
139
	{
140
		for (CList<SStringList>::iterator itr = _lList->begin(); itr != _lList->end(); itr++) {
141
			if ((*itr)->str.Compare(str, !bIgnoreCase))
142
				return true;
143
		}
144
 
145
		return false;
146
	}
147
 
148
	void CStringList::removeAt(int at)
149
	{
150
		_lList->removeAt(at);
151
	}
152
	bool CStringList::remove(const Utils::String &str, bool single)
153
	{
154
		bool removed = false;
155
 
156
		CList<Utils::SStringList>::iterator itr = _lList->begin();
157
		while (itr != _lList->end())
158
		{
159
			Utils::SStringList *node = *itr;
160
			if (node->str == str)
161
			{
162
				itr = _lList->remove(itr);
163
				if (single)
164
					break;
165
			}
166
			else
167
				++itr;
168
		}
169
 
170
 
171
		return removed;
172
	}
173
 
174
 
175
 
176
 
112 cycrow 177
	size_t CStringList::size() const
178
	{
179
		return _lList->size();
180
	}
181
 
182
	bool CStringList::empty() const
183
	{
184
		return _lList->empty();
185
	}
8 cycrow 186
}