Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -23,18 +23,11 @@ #define IRC_CONNECTION_M #include -#import -#import -#import -#import - -#import - -#import +#import #import "IRCConnection.h" #import "IRCUser.h" @interface IRCConnection () @@ -89,11 +82,11 @@ - (void)connect { void *pool = objc_autoreleasePoolPush(); if (_socket != nil) - @throw [OFAlreadyConnectedException exception]; + @throw [OFAlreadyOpenException exceptionWithObject: self]; _socket = [[_socketClass alloc] init]; [_socket setDelegate: self]; [_socket asyncConnectToHost: _server port: _port]; @@ -254,14 +247,14 @@ [_delegate connection: self didReceiveLine: line]; components = [line componentsSeparatedByString: @" "]; /* PING */ - if ([components count] == 2 && - [[components firstObject] isEqual: @"PING"]) { + if (components.count == 2 && + [components.firstObject isEqual: @"PING"]) { OFMutableString *s = [[line mutableCopy] autorelease]; - [s replaceCharactersInRange: OFRangeMake(0, 4) + [s replaceCharactersInRange: OFMakeRange(0, 4) withString: @"PONG"]; [self sendLine: s]; return; } @@ -300,11 +293,11 @@ OFString *who = [components objectAtIndex: 0]; OFString *where = [components objectAtIndex: 2]; IRCUser *user; OFMutableSet *channel; - who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; + who = [who substringFromIndex: 1]; user = [IRCUser IRCUserWithString: who]; if ([who hasPrefix: [_nickname stringByAppendingString: @"!"]]) { channel = [OFMutableSet set]; @@ -342,18 +335,17 @@ [[components objectAtIndex: 2] length] + [[components objectAtIndex: 3] length] + [[components objectAtIndex: 4] length] + 6; users = [[line substringWithRange: - OFRangeMake(pos, line.length - pos)] + OFMakeRange(pos, line.length - pos)] componentsSeparatedByString: @" "]; for (OFString *user in users) { if ([user hasPrefix: @"@"] || [user hasPrefix: @"+"] || [user hasPrefix: @"%"] || [user hasPrefix: @"*"]) - user = [user substringWithRange: - OFRangeMake(1, user.length - 1)]; + user = [user substringFromIndex: 1]; [channel addObject: user]; } if ([_delegate respondsToSelector: @@ -372,17 +364,16 @@ OFMutableSet *channel; OFString *reason = nil; size_t pos = who.length + 1 + [[components objectAtIndex: 1] length] + 1 + where.length; - who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; + who = [who substringFromIndex: 1]; user = [IRCUser IRCUserWithString: who]; channel = [_channels objectForKey: where]; if (components.count > 3) - reason = [line substringWithRange: - OFRangeMake(pos + 2, line.length - pos - 2)]; + reason = [line substringFromIndex: pos + 2]; [channel removeObject: user.nickname]; if ([_delegate respondsToSelector: @selector(connection:didSeeUser:leaveChannel:reason:)]) @@ -404,17 +395,16 @@ OFString *reason = nil; size_t pos = who.length + 1 + [[components objectAtIndex: 1] length] + 1 + where.length + 1 + whom.length; - who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; + who = [who substringFromIndex: 1]; user = [IRCUser IRCUserWithString: who]; channel = [_channels objectForKey: where]; - if ([components count] > 4) - reason = [line substringWithRange: - OFRangeMake(pos + 2, line.length - pos - 2)]; + if (components.count > 4) + reason = [line substringFromIndex: pos + 2]; [channel removeObject: user.nickname]; if ([_delegate respondsToSelector: @selector(connection:didSeeUser:kickUser:channel:reason:)]) @@ -433,16 +423,15 @@ IRCUser *user; OFString *reason = nil; size_t pos = who.length + 1 + [[components objectAtIndex: 1] length]; - who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; + who = [who substringFromIndex: 1]; user = [IRCUser IRCUserWithString: who]; if ([components count] > 2) - reason = [line substringWithRange: - OFRangeMake(pos + 2, line.length - pos - 2)]; + reason = [line substringFromIndex: pos + 2]; for (OFString *channel in _channels) [[_channels objectForKey: channel] removeObject: user.nickname]; @@ -459,13 +448,12 @@ if ([action isEqual: @"NICK"] && components.count == 3) { OFString *who = [components objectAtIndex: 0]; OFString *nickname = [components objectAtIndex: 2]; IRCUser *user; - who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; - nickname = [nickname substringWithRange: - OFRangeMake(1, nickname.length - 1)]; + who = [who substringFromIndex: 1]; + nickname = [nickname substringFromIndex: 1]; user = [IRCUser IRCUserWithString: who]; if ([user.nickname isEqual: _nickname]) { [_nickname release]; @@ -495,14 +483,12 @@ IRCUser *user; OFString *message; size_t pos = from.length + 1 + [[components objectAtIndex: 1] length] + 1 + to.length; - from = [from substringWithRange: - OFRangeMake(1, from.length - 1)]; - message = [line substringWithRange: - OFRangeMake(pos + 2, line.length - pos - 2)]; + from = [from substringFromIndex: 1]; + message = [line substringFromIndex: pos + 2]; user = [IRCUser IRCUserWithString: from]; if (![to isEqual: _nickname]) { if ([_delegate respondsToSelector: @selector(connection: didReceiveMessage:channel:user:)]) @@ -528,14 +514,12 @@ IRCUser *user = nil; OFString *notice; size_t pos = from.length + 1 + [[components objectAtIndex: 1] length] + 1 + to.length; - from = [from substringWithRange: - OFRangeMake(1, from.length - 1)]; - notice = [line substringWithRange: - OFRangeMake(pos + 2, line.length - pos - 2)]; + from = [from substringFromIndex: 1]; + notice = [line substringFromIndex: pos + 2]; if (![from containsString: @"!"] || [to isEqual: @"*"]) { /* System message - ignore for now */ return; } Index: tests/tests.m ================================================================== --- tests/tests.m +++ tests/tests.m @@ -31,11 +31,11 @@ @end OF_APPLICATION_DELEGATE(TestApp) @implementation TestApp -- (void)applicationDidFinishLaunching +- (void)applicationDidFinishLaunching: (OFNotification *)notification { IRCConnection *connection = [[IRCConnection alloc] init]; connection.server = @"irc.freenode.net"; connection.nickname = @"ObjIRC";