mirror of https://github.com/buggins/dlangui.git
fixes #217
This commit is contained in:
parent
9f37ee5257
commit
20c5fdaa83
|
@ -162,11 +162,11 @@ class IRCUser {
|
||||||
|
|
||||||
class UserList {
|
class UserList {
|
||||||
Collection!IRCUser _users;
|
Collection!IRCUser _users;
|
||||||
@property int length() { return _users.length; }
|
@property size_t length() { return _users.length; }
|
||||||
@property IRCUser opIndex(int index) { return _users[index]; }
|
@property IRCUser opIndex(size_t index) { return _users[index]; }
|
||||||
void fromList(string userList) {
|
void fromList(string userList) {
|
||||||
_users.clear();
|
_users.clear();
|
||||||
for(;;) {
|
while(true) {
|
||||||
string s = parseDelimitedParameter(userList);
|
string s = parseDelimitedParameter(userList);
|
||||||
if (s.empty)
|
if (s.empty)
|
||||||
break;
|
break;
|
||||||
|
@ -174,20 +174,22 @@ class UserList {
|
||||||
_users.add(u);
|
_users.add(u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int findUser(string name) {
|
import std.typecons : Tuple;
|
||||||
for(int i = 0; i < _users.length; i++) {
|
Tuple!(bool, "found", size_t, "index") findUser(string name) {
|
||||||
|
foreach(i; 0.._users.length) {
|
||||||
if (_users[i].nick == name)
|
if (_users[i].nick == name)
|
||||||
return i;
|
return typeof(return)(true, i);
|
||||||
}
|
}
|
||||||
return -1;
|
return typeof(return)(false, 0);
|
||||||
}
|
}
|
||||||
void addUser(string name) {
|
void addUser(string name) {
|
||||||
if (findUser(name) < 0)
|
if (findUser(name).found == false)
|
||||||
_users.add(new IRCUser(name));
|
_users.add(new IRCUser(name));
|
||||||
}
|
}
|
||||||
void removeUser(string name) {
|
void removeUser(string name) {
|
||||||
if (int index = findUser(name)) {
|
auto user = findUser(name);
|
||||||
_users.remove(index);
|
if (user.found) {
|
||||||
|
_users.remove(user.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue