Definition at line 23 of file StringArray.h.
◆ StringArray() [1/2]
StringArray::StringArray |
( |
int |
startsize = 0 | ) |
|
Definition at line 28 of file StringArray.cpp.
29{
30 count = startsize;
31 size = (startsize + alloc) / alloc * alloc;
32 strings =
new String * [size];
33 for (int i = 0; i < count; i++)
35 for (int i = count; i < size; i++)
36 strings[i] = NULL;
37};
◆ StringArray() [2/2]
Definition at line 39 of file StringArray.cpp.
40{
41 count = rhs.count;
42 size = (rhs.count + alloc) / alloc * alloc;
43 strings =
new String * [size];
44
45 for (int i = 0; i < count; i++)
46 strings[i] =
new String(rhs[i]);;
47 for (int i = count; i < size; i++)
48 strings[i] = NULL;
49}
◆ ~StringArray()
StringArray::~StringArray |
( |
| ) |
|
|
virtual |
Definition at line 51 of file StringArray.cpp.
52{
53 for (int i = 0; i < size; i++)
54 if (strings[i] != NULL)
55 delete strings[i];
56 else
57 break;
58
59 delete [] strings;
60}
◆ Add()
int StringArray::Add |
( |
const String & |
s | ) |
|
Definition at line 327 of file StringArray.cpp.
328{
329 Grow(count + 1);
330 if (strings[count] == NULL)
331 {
332 strings[count] =
new String(s);
333 }
334 else
335 {
336 *strings[count] = s;
337 }
338 return ++count;
339}
◆ AddColumns() [1/2]
int StringArray::AddColumns |
( |
const String & |
s, |
|
|
char |
ch, |
|
|
int |
maxColumns |
|
) |
| |
Definition at line 199 of file StringArray.cpp.
200{
201 maxColumns += count;
202
203 if (s.Length() > 0)
204 for (int pos = 0; pos <= s.Length() && maxColumns != count; pos++)
205 {
206 int oldpos = pos;
207 pos = s.FindChar(ch, pos);
208 if (pos == -1) pos = s.Length();
209 Grow(count + 1);
210
211 if (strings[count] == NULL)
212 strings[count] =
new String(pos - oldpos);
213 strings[count]->SetLength(pos - oldpos);
214 memcpy((char *) *strings[count++], ((const char *) s) + oldpos, pos - oldpos);
215 };
216
217 return count;
218}
◆ AddColumns() [2/2]
int StringArray::AddColumns |
( |
const String & |
s, |
|
|
char |
ch = '\t' |
|
) |
| |
Definition at line 178 of file StringArray.cpp.
179{
180 if (s.Length() > 0)
181 for (int pos = 0; pos <= s.Length(); pos++)
182 {
183 int oldpos = pos;
184 pos = s.FindChar(ch, pos);
185 if (pos == -1) pos = s.Length();
186 Grow(count + 1);
187
188 if (strings[count] == NULL)
189 {
190 strings[count] =
new String(pos - oldpos);
191 }
192 strings[count]->SetLength(pos - oldpos);
193 memcpy((char *) *strings[count++], ((const char *) s) + oldpos, pos - oldpos);
194 }
195
196 return count;
197}
◆ AddTokens() [1/2]
int StringArray::AddTokens |
( |
const String & |
s, |
|
|
char |
ch |
|
) |
| |
Definition at line 220 of file StringArray.cpp.
221{
222 for (int pos = 0; pos < s.Length(); pos++)
223 {
224 while (pos < s.Length() && s[pos] == ch) pos++;
225 int oldpos = pos;
226
227 while (pos < s.Length() && s[pos] != ch) pos++;
228
229 if (oldpos < s.Length())
230 {
231 Grow(count + 1);
232 if (strings[count] == NULL)
233 {
234 strings[count] =
new String(pos - oldpos);
235 }
236 strings[count]->SetLength(pos - oldpos);
237 memcpy((char *) *strings[count++], (const char *) s + oldpos, pos - oldpos);
238 }
239 }
240
241 return count;
242}
◆ AddTokens() [2/2]
int StringArray::AddTokens |
( |
const String & |
s, |
|
|
const String & |
separators = " \t\r\n" |
|
) |
| |
Definition at line 244 of file StringArray.cpp.
245{
246 for (int pos = 0; pos < s.Length(); pos++)
247 {
248 while (pos < s.Length() && separators.FindChar(s[pos]) != -1) pos++;
249 int oldpos = pos;
250
251 while (pos < s.Length() && separators.FindChar(s[pos]) == -1) pos++;
252
253 if (oldpos < s.Length())
254 {
255 Grow(count + 1);
256 if (strings[count] == NULL)
257 strings[count] =
new String(pos - oldpos);
258 strings[count]->SetLength(pos - oldpos);
259 memcpy((char *) *strings[count++], ((const char *) s) + oldpos, pos - oldpos);
260 }
261 }
262
263 return count;
264}
◆ CharLength()
int StringArray::CharLength |
( |
| ) |
|
Definition at line 62 of file StringArray.cpp.
63{
64 int charlen = 0;
65 for (int i = 0; i < count; i++)
66 charlen += strings[i]->Length();
67 return charlen;
68}
◆ Clear()
void StringArray::Clear |
( |
| ) |
|
Definition at line 158 of file StringArray.cpp.
159{
160 if (!lazyMemoryManagement)
161 {
162 for (int i = 0; i < size; i++)
163 {
164 if (strings[i] != NULL)
165 {
166 delete strings[i];
167 strings[i] = NULL;
168 }
169 else
170 {
171 break;
172 }
173 }
174 }
175 count = 0;
176}
◆ Delete()
void StringArray::Delete |
( |
int |
position | ) |
|
Definition at line 363 of file StringArray.cpp.
364{
365 String * oldString = strings[index];
366
367 count--;
368 for (; index < count; index++)
369 strings[index] = strings[index + 1];
370 strings[count] = oldString;
371}
◆ Dimension()
int StringArray::Dimension |
( |
int |
newcount | ) |
|
Definition at line 266 of file StringArray.cpp.
267{
268 if (newcount > count)
269 {
270 Grow(newcount);
271 for (int i = count; i < newcount; i++)
272 {
273 if (strings[i] == NULL)
275 else
276 strings[i]->Clear();
277 }
278 count = newcount;
279 }
280 else if (newcount < count)
281 {
282 if (!lazyMemoryManagement)
283 {
284 for (int i = newcount; i < size; i++)
285 {
286 if (strings[i] != NULL)
287 {
288 delete strings[i];
289 strings[i] = NULL;
290 }
291 else
292 {
293 break;
294 }
295 }
296 }
297 count = newcount;
298 }
299
300 return count;
301}
◆ FastFind()
int StringArray::FastFind |
( |
const String & |
s | ) |
const |
Definition at line 311 of file StringArray.cpp.
312{
313 for (int i = 0; i < count; i++)
314 if (strings[i]->FastCompare(s) == 0)
315 return i;
316 return -1;
317}
◆ Find()
int StringArray::Find |
( |
const String & |
s | ) |
const |
Definition at line 303 of file StringArray.cpp.
304{
305 for (int i = 0; i < count; i++)
306 if (*(strings[i]) == s)
307 return i;
308 return -1;
309}
◆ Grow()
void StringArray::Grow |
( |
int |
newsize | ) |
|
Definition at line 134 of file StringArray.cpp.
135{
136 if (newsize >= size)
137 {
138 int oldsize = size;
139
140 if ((newsize >> 1) >= size)
141 size = (newsize + alloc) / alloc * alloc;
142 else
143 {
144 size = alloc;
145 while (size <= newsize)
146 size *= 2;
147 }
149 for (int i = 0; i < oldsize; i++)
150 tmp[i] = strings[i];
151 for (int i = oldsize; i < size; i++)
152 tmp[i] = NULL;
153 delete [] strings;
154 strings = tmp;
155 }
156}
◆ InsertAt()
void StringArray::InsertAt |
( |
int |
position, |
|
|
const String & |
s |
|
) |
| |
Definition at line 341 of file StringArray.cpp.
342{
343 Grow(count + 1);
344
345 String * newString = strings[count];
346 if (newString == NULL)
347 newString =
new String(s);
348 else
349 *newString = s;
350
351 for (int i = count; i > position; i--)
352 strings[i] = strings[i - 1];
353 strings[position] = newString;
354 count++;
355}
◆ Last()
String & StringArray::Last |
( |
| ) |
const |
Definition at line 357 of file StringArray.cpp.
358{
359 if (!count) error("StringArray: Null String Access");
360 return *(strings[count - 1]);
361}
◆ Length()
int StringArray::Length |
( |
| ) |
const |
|
inline |
◆ operator!=()
bool StringArray::operator!= |
( |
const StringArray & |
rhs | ) |
const |
|
inline |
Definition at line 131 of file StringArray.h.
132 {
133 return !(*this == rhs);
134 }
◆ operator=()
Definition at line 373 of file StringArray.cpp.
374{
375 Dimension(rhs.count);
376 for (int i = 0; i < rhs.count; i++)
377 *strings[i] = *rhs.strings[i];
378 return *this;
379}
◆ operator==()
bool StringArray::operator== |
( |
const StringArray & |
rhs | ) |
const |
Definition at line 381 of file StringArray.cpp.
382{
383 if (count != rhs.count) return false;
384 for (int i = 0; i < rhs.count; i++)
385 if (*strings[i] != *rhs.strings[i])
386 return false;
387 return true;
388}
◆ operator[]() [1/2]
String & StringArray::operator[] |
( |
int |
i | ) |
|
|
inline |
Definition at line 67 of file StringArray.h.
68 {
69 return *(strings[i]);
70 }
◆ operator[]() [2/2]
const String & StringArray::operator[] |
( |
int |
i | ) |
const |
|
inline |
Definition at line 71 of file StringArray.h.
72 {
73 return *(strings[i]);
74 }
◆ Pop()
Definition at line 403 of file StringArray.cpp.
404{
405 String result = *(strings[count - 1]);
406
407 Dimension(count - 1);
408
409 return result;
410}
◆ Print() [1/2]
void StringArray::Print |
( |
| ) |
|
◆ Print() [2/2]
void StringArray::Print |
( |
FILE * |
f | ) |
|
Definition at line 423 of file StringArray.cpp.
424{
425 for (int i = 0; i < count; i++)
426 fprintf(output, "%s\n", (const char *)(*strings[i]));
427}
◆ PrintLine() [1/2]
void StringArray::PrintLine |
( |
| ) |
|
◆ PrintLine() [2/2]
void StringArray::PrintLine |
( |
FILE * |
f | ) |
|
Definition at line 434 of file StringArray.cpp.
435{
436 for (int i = 0; i < count; i++)
437 fprintf(output, "%s%c", (const char *)(*strings[i]), i == count - 1 ? '\n' : '\t');
438}
◆ Push()
int StringArray::Push |
( |
const String & |
s | ) |
|
|
inline |
◆ Read() [1/3]
void StringArray::Read |
( |
const char * |
filename | ) |
|
Definition at line 70 of file StringArray.cpp.
71{
73 if (f == NULL) return;
74 Read(f);
76}
◆ Read() [2/3]
void StringArray::Read |
( |
FILE * |
f | ) |
|
Definition at line 94 of file StringArray.cpp.
95{
96 while (!feof(f))
97 {
98 Grow(count + 1);
99 if (strings[count] == NULL)
100 strings[count] =
new String;
101 strings[count]->ReadLine(f);
102 count++;
103 }
104}
◆ Read() [3/3]
void StringArray::Read |
( |
IFILE & |
f | ) |
|
Definition at line 118 of file StringArray.cpp.
119{
121 {
122 Grow(count + 1);
123 if (strings[count] == NULL)
124 strings[count] =
new String;
125 strings[count]->ReadLine(f);
126 if (
ifeof(f) && strings[count]->Length()==0)
127 {
128 return;
129 }
130 count++;
131 }
132}
◆ ReplaceColumns()
int StringArray::ReplaceColumns |
( |
const String & |
s, |
|
|
char |
ch = '\t' |
|
) |
| |
|
inline |
Definition at line 85 of file StringArray.h.
86 {
87 Clear();
88 return AddColumns(s, ch);
89 }
◆ ReplaceTokens()
int StringArray::ReplaceTokens |
( |
const String & |
s, |
|
|
const String & |
separators = " \t\r\n" |
|
) |
| |
|
inline |
Definition at line 90 of file StringArray.h.
91 {
92 Clear();
93 return AddTokens(s, separators);
94 }
◆ SlowFind()
int StringArray::SlowFind |
( |
const String & |
s | ) |
const |
Definition at line 319 of file StringArray.cpp.
320{
321 for (int i = 0; i < count; i++)
322 if (strings[i]->SlowCompare(s) == 0)
323 return i;
324 return -1;
325}
◆ Sort()
void StringArray::Sort |
( |
| ) |
|
Definition at line 390 of file StringArray.cpp.
391{
392 QuickSort(strings, count,
sizeof(
String *), ComparisonForSort);
393}
◆ Swap()
Definition at line 440 of file StringArray.cpp.
441{
442 String ** temp = s.strings;
443 s.strings = strings;
444 strings = temp;
445
446 int swap = s.size;
447 s.size = size;
448 size = swap;
449
450 swap = s.count;
451 s.count = count;
452 count = swap;
453}
◆ Trim()
void StringArray::Trim |
( |
| ) |
|
Definition at line 412 of file StringArray.cpp.
413{
414 for (int i = 0; i < count; i++)
415 strings[i]->Trim();
416}
◆ Write() [1/2]
void StringArray::Write |
( |
const char * |
filename | ) |
|
Definition at line 78 of file StringArray.cpp.
79{
80 FILE * f = fopen(filename, "wt");
81 if (f == NULL) return;
82 Write(f);
83 fclose(f);
84}
◆ Write() [2/2]
void StringArray::Write |
( |
FILE * |
f | ) |
|
Definition at line 106 of file StringArray.cpp.
107{
108 for (int i = 0; i < count; i++)
109 strings[i]->WriteLine(f);
110}
◆ WriteLine() [1/2]
void StringArray::WriteLine |
( |
const char * |
filename | ) |
|
Definition at line 86 of file StringArray.cpp.
87{
88 FILE * f = fopen(filename, "wt");
89 if (f == NULL) return;
90 WriteLine(f);
91 fclose(f);
92}
◆ WriteLine() [2/2]
void StringArray::WriteLine |
( |
FILE * |
f | ) |
|
Definition at line 112 of file StringArray.cpp.
113{
114 for (int i = 0; i < count; i++)
115 fprintf(f, "%s%c", (const char *)(*strings[i]), i == count-1 ? '\n' : '\t');
116}
◆ alloc
int StringArray::alloc = 32 |
|
static |
◆ count
◆ lazyMemoryManagement
bool StringArray::lazyMemoryManagement = false |
|
static |
◆ size
◆ strings
The documentation for this class was generated from the following files: