From a881575bf3c44058b74a21511a6dbf222bb37c59 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sat, 17 Aug 2024 00:19:23 +0000 Subject: [PATCH] Don't use private ObjFW functions FossilOrigin-Name: 3e008e29646a6eaeccbc4560352d3444691e9bee4da9ef70be30408df6ecb4b1 --- src/IRCUser.m | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/IRCUser.m b/src/IRCUser.m index f666157..1c29ed0 100644 --- a/src/IRCUser.m +++ b/src/IRCUser.m @@ -43,34 +43,28 @@ - (instancetype)initWithString: (OFString *)string { - char *tmp2 = NULL; - self = [super init]; @try { - char *tmp; + size_t pos; - tmp2 = OFStrDup(string.UTF8String); - - if ((tmp = strchr(tmp2, '@')) == NULL) + pos = [string rangeOfString: @"@"].location; + if (pos == OFNotFound) @throw [OFInvalidFormatException exception]; - *tmp = '\0'; - _hostname = [[OFString alloc] initWithUTF8String: tmp + 1]; + _hostname = [[string substringFromIndex: pos + 1] copy]; - if ((tmp = strchr(tmp2, '!')) == NULL) + string = [string substringToIndex: pos]; + + pos = [string rangeOfString: @"!"].location; + if (pos == OFNotFound) @throw [OFInvalidFormatException exception]; - *tmp = '\0'; - _username = [[OFString alloc] initWithUTF8String: tmp + 1]; - - _nickname = [[OFString alloc] initWithUTF8String: tmp2]; + _username = [[string substringFromIndex: pos + 1] copy]; + _nickname = [[string substringToIndex: pos] copy]; } @catch (id e) { [self release]; @throw e; - } @finally { - if (tmp2 != NULL) - free(tmp2); } return self;