5 #include "StringList.h"
6 #include "StringList.fdh"
9 StringList::~StringList()
15 void c------------------------------() {}
18 void StringList::Shuffle()
20 int i
, count
= CountItems();
24 int swap
= random(0, count
- 1);
32 bool StringList::ContainsString(const char *term
)
37 for(i
=0; (str
= StringAt(i
)); i
++)
39 if (!strcmp(str
, term
))
46 bool StringList::ContainsCaseString(const char *term
)
51 for(i
=0; (str
= StringAt(i
)); i
++)
53 if (!strcasecmp(str
, term
))
61 void c------------------------------() {}
64 void StringList::AddString(const char *str
)
66 BList::AddItem(strdup(str
));
69 bool StringList::SetString(int index
, const char *newstring
)
71 char *str
= StringAt(index
);
73 if (str
== newstring
) return 0;
75 int copylen
= strlen(newstring
) + 1;
76 str
= (char *)realloc(str
, copylen
);
77 memcpy(str
, newstring
, copylen
);
79 BList::ReplaceItem(index
, str
);
83 void StringList::RemoveString(int index
)
85 char *str
= StringAt(index
);
88 BList::RemoveItem(index
);
93 void StringList::RemoveString(const char *str
)
98 for(i
=0; (entry
= StringAt(i
)); i
++)
100 if (!strcmp(entry
, str
))
102 BList::RemoveItem(i
);
109 void StringList::RemoveIString(const char *str
)
114 for(i
=0; (entry
= StringAt(i
)); i
++)
116 if (!strcasecmp(entry
, str
))
118 BList::RemoveItem(i
);
126 void c------------------------------() {}
129 void StringList::SwapItems(int index1
, int index2
)
131 BList::SwapItems(index1
, index2
);
134 void StringList::DumpContents()
136 int i
, count
= CountItems();
138 stat("StringList %08x; %d entries", this, count
);
141 char *str
= StringAt(i
);
142 stat("(%d) <%08x>: '%s'", i
, str
, str
? str
: "(null)");
147 void c------------------------------() {}
150 char *StringList::StringAt(int index
) const
152 return (char *)BList::ItemAt(index
);
155 void StringList::MakeEmpty()
157 int i
, count
= CountItems();
167 void c------------------------------() {}
170 StringList
&StringList::operator= (const StringList
&other
)
172 StringList::MakeEmpty();
176 char *str
= other
.StringAt(i
);
185 bool StringList::operator== (const StringList
&other
) const
187 if (CountItems() != other
.CountItems())
192 char *str1
= StringAt(i
);
193 char *str2
= other
.StringAt(i
);
196 return (!str1
&& !str2
);
198 if (strcmp(str1
, str2
) != 0)
203 bool StringList::operator!= (const StringList
&other
) const
205 return !(*this == other
);