Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -257,14 +257,12 @@ "Warning: Invalid environment " "variable: %s\n", tmp.UTF8String); continue; } - key = [tmp substringWithRange: - of_range(0, pos)]; - value = [tmp substringWithRange: - of_range(pos + 1, tmp.length - pos - 1)]; + key = [tmp substringToIndex: pos]; + value = [tmp substringFromRange: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); @@ -303,14 +301,12 @@ "Warning: Invalid environment " "variable: %s\n", tmp.UTF8String); continue; } - key = [tmp substringWithRange: - of_range(0, pos)]; - value = [tmp substringWithRange: - of_range(pos + 1, tmp.length - pos - 1)]; + key = [tmp substringToIndex: pos]; + value = [tmp substringFromIndex: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -402,10 +402,24 @@ { [self finishInitialization]; return [self containsString: string]; } + +- (OFString *)substringFromIndex: (size_t)idx +{ + [self finishInitialization]; + + return [self substringFromIndex: idx]; +} + +- (OFString *)substringToIndex: (size_t)idx +{ + [self finishInitialization]; + + return [self substringToIndex: idx]; +} - (OFString *)substringWithRange: (of_range_t)range { [self finishInitialization]; Index: src/OFDNSResolverSettings.m ================================================================== --- src/OFDNSResolverSettings.m +++ src/OFDNSResolverSettings.m @@ -93,12 +93,11 @@ size_t pos = [domain rangeOfString: @"."].location; if (pos == OF_NOT_FOUND) return nil; - ret = [domain substringWithRange: - of_range(pos + 1, domain.length - pos - 1)]; + ret = [domain substringFromIndex: pos + 1]; } return ret; } #endif @@ -192,11 +191,11 @@ size_t pos; OFString *address; pos = [line rangeOfString: @"#"].location; if (pos != OF_NOT_FOUND) - line = [line substringWithRange: of_range(0, pos)]; + line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OF_STRING_SKIP_EMPTY]; @@ -241,37 +240,33 @@ { @try { if ([option hasPrefix: @"ndots:"]) { unsigned long long number; - option = [option substringWithRange: - of_range(6, option.length - 6)]; + option = [option substringFromIndex: 6]; number = option.unsignedLongLongValue; if (number > UINT_MAX) @throw [OFOutOfRangeException exception]; _minNumberOfDotsInAbsoluteName = (unsigned int)number; } else if ([option hasPrefix: @"timeout:"]) { - option = [option substringWithRange: - of_range(8, option.length - 8)]; + option = [option substringFromIndex: 8]; _timeout = option.unsignedLongLongValue; } else if ([option hasPrefix: @"attempts:"]) { unsigned long long number; - option = [option substringWithRange: - of_range(9, option.length - 9)]; + option = [option substringFromIndex: 9]; number = option.unsignedLongLongValue; if (number > UINT_MAX) @throw [OFOutOfRangeException exception]; _maxAttempts = (unsigned int)number; } else if ([option hasPrefix: @"reload-period:"]) { - option = [option substringWithRange: - of_range(14, option.length - 14)]; + option = [option substringFromIndex: 14]; _configReloadInterval = option.unsignedLongLongValue; } else if ([option isEqual: @"tcp"]) _usesTCP = true; } @catch (OFInvalidFormatException *e) { @@ -306,11 +301,11 @@ OFArray *components, *arguments; OFString *option; pos = [line indexOfCharacterFromSet: commentCharacters]; if (pos != OF_NOT_FOUND) - line = [line substringWithRange: of_range(0, pos)]; + line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OF_STRING_SKIP_EMPTY]; Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -1000,11 +1000,11 @@ return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; - of_range_t range; + size_t pos; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; @@ -1011,22 +1011,20 @@ } if (line == nil) return 0; - range = [line rangeOfString: @";"]; - if (range.location != OF_NOT_FOUND) - line = [line substringWithRange: - of_range(0, range.location)]; + pos = [line rangeOfString: @";"].location; + if (pos != OF_NOT_FOUND) + line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ - if (_socket.atEndOfStream && - range.location == OF_NOT_FOUND) + if (_socket.atEndOfStream && pos == OF_NOT_FOUND) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidServerReplyException exception]; } Index: src/OFHTTPCookieManager.m ================================================================== --- src/OFHTTPCookieManager.m +++ src/OFHTTPCookieManager.m @@ -136,12 +136,12 @@ URLHost = URL.host.lowercaseString; if ([cookieDomain hasPrefix: @"."]) { if ([URLHost hasSuffix: cookieDomain]) match = true; else { - cookieDomain = [cookieDomain substringWithRange: - of_range(1, cookieDomain.length - 1)]; + cookieDomain = + [cookieDomain substringFromIndex: 1]; match = [cookieDomain isEqual: URLHost]; } } else match = [cookieDomain isEqual: URLHost]; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -374,11 +374,11 @@ pos = [line rangeOfString: @" "].location; if (pos == OF_NOT_FOUND) return [self sendErrorAndClose: 400]; - method = [line substringWithRange: of_range(0, pos)]; + method = [line substringToIndex: pos]; @try { _method = of_http_request_method_from_string(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @@ -450,13 +450,12 @@ pos = [line rangeOfString: @":"].location; if (pos == OF_NOT_FOUND) return [self sendErrorAndClose: 400]; - key = [line substringWithRange: of_range(0, pos)]; - value = [line substringWithRange: - of_range(pos + 1, line.length - pos - 1)]; + key = [line substringToIndex: pos]; + value = [line substringFromIndex: pos + 1]; key = normalizedKey(key.stringByDeletingTrailingWhitespaces); value = value.stringByDeletingLeadingWhitespaces; old = [_headers objectForKey: key]; @@ -471,18 +470,15 @@ rangeOfString: @":" options: OF_STRING_SEARCH_BACKWARDS].location; if (pos != OF_NOT_FOUND) { [_host release]; - _host = [[value substringWithRange: - of_range(0, pos)] retain]; + _host = [[value substringToIndex: pos] retain]; @try { - of_range_t range = - of_range(pos + 1, value.length - pos - 1); unsigned long long portTmp = - [value substringWithRange: range] + [value substringFromIndex: pos + 1] .unsignedLongLongValue; if (portTmp < 1 || portTmp > UINT16_MAX) return [self sendErrorAndClose: 400]; @@ -546,13 +542,12 @@ URL.port = [OFNumber numberWithUnsignedShort: _port]; if ((pos = [_path rangeOfString: @"?"].location) != OF_NOT_FOUND) { OFString *path, *query; - path = [_path substringWithRange: of_range(0, pos)]; - query = [_path substringWithRange: - of_range(pos + 1, _path.length - pos - 1)]; + path = [_path substringToIndex: pos]; + query = [_path substringFromIndex: pos + 1]; URL.URLEncodedPath = path; URL.URLEncodedQuery = query; } else URL.URLEncodedPath = _path; @@ -696,11 +691,11 @@ return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; - of_range_t range; + size_t pos; unsigned long long toRead; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @@ -708,22 +703,20 @@ } if (line == nil) return 0; - range = [line rangeOfString: @";"]; - if (range.location != OF_NOT_FOUND) - line = [line substringWithRange: - of_range(0, range.location)]; + pos = [line rangeOfString: @";"].location; + if (pos != OF_NOT_FOUND) + line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ - if (_socket.atEndOfStream && - range.location == OF_NOT_FOUND) + if (_socket.atEndOfStream && pos == OF_NOT_FOUND) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidFormatException exception]; } Index: src/OFINICategory.m ================================================================== --- src/OFINICategory.m +++ src/OFINICategory.m @@ -159,19 +159,14 @@ size_t pos; if ((pos = [line rangeOfString: @"="].location) == OF_NOT_FOUND) @throw [OFInvalidFormatException exception]; - key = [line substringWithRange: of_range(0, pos)]; - value = [line substringWithRange: - of_range(pos + 1, line.length - pos - 1)]; - - key = key.stringByDeletingEnclosingWhitespaces; - value = value.stringByDeletingEnclosingWhitespaces; - - key = unescapeString(key); - value = unescapeString(value); + key = unescapeString([line substringToIndex: pos] + .stringByDeletingEnclosingWhitespaces); + value = unescapeString([line substringFromIndex: pos + 1] + .stringByDeletingEnclosingWhitespaces); pair->_key = [key copy]; pair->_value = [value copy]; [_lines addObject: pair]; Index: src/OFINIFileSettings.m ================================================================== --- src/OFINIFileSettings.m +++ src/OFINIFileSettings.m @@ -65,13 +65,12 @@ *category = @""; *key = path; return; } - *category = [path substringWithRange: of_range(0, pos)]; - *key = [path substringWithRange: - of_range(pos + 1, path.length - pos - 1)]; + *category = [path substringToIndex: pos]; + *key = [path substringFromIndex: pos + 1]; } - (void)setString: (OFString *)string forPath: (OFString *)path { Index: src/OFOptionsParser.m ================================================================== --- src/OFOptionsParser.m +++ src/OFOptionsParser.m @@ -195,16 +195,14 @@ _lastOption = '-'; _index++; if ((pos = [argument rangeOfString: @"="].location) != - OF_NOT_FOUND) { - of_range_t range = of_range(pos + 1, - argument.length - pos - 1); + OF_NOT_FOUND) _argument = [[argument - substringWithRange: range] copy]; - } else + substringFromIndex: pos + 1] copy]; + else pos = argument.length; _lastLongOption = [[argument substringWithRange: of_range(2, pos - 2)] copy]; @@ -253,12 +251,11 @@ if (_index >= _arguments.count) return ':'; argument = [_arguments objectAtIndex: _index]; - argument = [argument substringWithRange: - of_range(_subIndex, argument.length - _subIndex)]; + argument = [argument substringFromIndex: _subIndex]; _argument = [argument copy]; if (iter->isSpecifiedPtr != NULL) *iter->isSpecifiedPtr = true; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -1002,10 +1002,26 @@ * @param string The string to search * @return Whether the string contains the specified string */ - (bool)containsString: (OFString *)string; +/** + * @brief Creates a substring from the specified index to the end. + * + * @param idx The index from where the substring should start, inclusive + * @return The substring from the specified index to the end + */ +- (OFString *)substringFromIndex: (size_t)idx; + +/** + * @brief Creates a substring from the beginning to the specified index. + * + * @param idx The index at which the substring should end, exclusive + * @return The subtring from the beginning to the specified index + */ +- (OFString *)substringToIndex: (size_t)idx; + /** * @brief Creates a substring with the specified range. * * @param range The range of the substring * @return The substring as a new autoreleased OFString Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1982,10 +1982,20 @@ objc_autoreleasePoolPop(pool); return false; } + +- (OFString *)substringFromIndex: (size_t)idx +{ + return [self substringWithRange: of_range(idx, self.length - idx)]; +} + +- (OFString *)substringToIndex: (size_t)idx +{ + return [self substringWithRange: of_range(0, idx)]; +} - (OFString *)substringWithRange: (of_range_t)range { void *pool; OFString *ret; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -1003,11 +1003,11 @@ objc_autoreleasePoolPop(pool); return @"/"; } if ([path hasSuffix: @"/"]) - path = [path substringWithRange: of_range(0, path.length - 1)]; + path = [path substringToIndex: path.length - 1]; UTF8String = lastComponent = path.UTF8String; length = path.UTF8StringLength; for (size_t i = 1; i <= length; i++) { Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -414,11 +414,11 @@ if (!self->_acceptProlog) return false; self->_acceptProlog = false; - pi = [pi substringWithRange: of_range(3, pi.length - 3)]; + pi = [pi substringFromIndex: 3]; pi = pi.stringByDeletingEnclosingWhitespaces; cString = pi.UTF8String; length = pi.UTF8StringLength; Index: src/platform/amiga/OFString+PathAdditions.m ================================================================== --- src/platform/amiga/OFString+PathAdditions.m +++ src/platform/amiga/OFString+PathAdditions.m @@ -125,12 +125,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } - ret = [fileName substringWithRange: - of_range(pos + 1, fileName.length - pos - 1)]; + ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -185,11 +184,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } - fileName = [fileName substringWithRange: of_range(0, pos)]; + fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; @@ -303,16 +302,16 @@ - (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) - path = [path substringWithRange: of_range(0, path.length - 1)]; + path = [path substringToIndex: path.length - 1]; OFMutableArray OF_GENERIC(OFString *) *components; size_t count; - path = [path substringWithRange: of_range(1, path.length - 1)]; + path = [path substringFromIndex: 1]; components = [[[path componentsSeparatedByString: @"/"] mutableCopy] autorelease]; count = components.count; for (size_t i = 0; i < count; i++) { Index: src/platform/libfat/OFString+PathAdditions.m ================================================================== --- src/platform/libfat/OFString+PathAdditions.m +++ src/platform/libfat/OFString+PathAdditions.m @@ -159,12 +159,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } - ret = [fileName substringWithRange: - of_range(pos + 1, fileName.length - pos - 1)]; + ret = [fileName substringWithFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -230,11 +229,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } - fileName = [fileName substringWithRange: of_range(0, pos)]; + fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; @@ -332,15 +331,15 @@ - (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) - path = [path substringWithRange: of_range(0, path.length - 1)]; + path = [path substringToIndex: path.length - 1]; - return [path substringWithRange: of_range(1, path.length - 1)]; + return [path substringFromIndex: 1]; } - (OFString *)of_pathComponentToURLPathComponent { return self; } @end Index: src/platform/posix/OFString+PathAdditions.m ================================================================== --- src/platform/posix/OFString+PathAdditions.m +++ src/platform/posix/OFString+PathAdditions.m @@ -152,12 +152,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } - ret = [fileName substringWithRange: - of_range(pos + 1, fileName.length - pos - 1)]; + ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -222,11 +221,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } - fileName = [fileName substringWithRange: of_range(0, pos)]; + fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; @@ -332,15 +331,15 @@ - (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) - path = [path substringWithRange: of_range(0, path.length - 1)]; + path = [path substringToIndex: path.length - 1]; return path; } - (OFString *)of_pathComponentToURLPathComponent { return self; } @end Index: src/platform/windows/OFString+PathAdditions.m ================================================================== --- src/platform/windows/OFString+PathAdditions.m +++ src/platform/windows/OFString+PathAdditions.m @@ -163,12 +163,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } - ret = [fileName substringWithRange: - of_range(pos + 1, fileName.length - pos - 1)]; + ret = [fileName substringFromIndex: pos + 1]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -233,11 +232,11 @@ if (pos == OF_NOT_FOUND || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } - fileName = [fileName substringWithRange: of_range(0, pos)]; + fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; ret = [OFString pathWithComponents: components]; @@ -356,13 +355,13 @@ { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"] && ![path hasSuffix: @":/"]) - path = [path substringWithRange: of_range(0, path.length - 1)]; + path = [path substringToIndex: path.length - 1]; - path = [path substringWithRange: of_range(1, path.length - 1)]; + path = [path substringFromIndex: 1]; path = [path stringByReplacingOccurrencesOfString: @"/" withString: @"\\"]; if (URLEncodedHost != nil) { OFString *host = [URLEncodedHost stringByURLDecoding]; Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -437,14 +437,12 @@ addrIn6->sin6_port = OF_BSWAP16_IF_LE(port); doubleColon = [IPv6 rangeOfString: @"::"].location; if (doubleColon != OF_NOT_FOUND) { - OFString *left = [IPv6 substringWithRange: - of_range(0, doubleColon)]; - OFString *right = [IPv6 substringWithRange: - of_range(doubleColon + 2, IPv6.length - doubleColon - 2)]; + OFString *left = [IPv6 substringToIndex: doubleColon]; + OFString *right = [IPv6 substringFromIndex: doubleColon + 2]; OFArray OF_GENERIC(OFString *) *leftComponents; OFArray OF_GENERIC(OFString *) *rightComponents; size_t i; if ([right hasPrefix: @":"] || [right containsString: @"::"]) Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -323,16 +323,15 @@ @"%[prog]: Headers must to be in format name:value!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } - name = [header substringWithRange: of_range(0, pos)]; - name = name.stringByDeletingEnclosingWhitespaces; + name = [header substringToIndex: pos] + .stringByDeletingEnclosingWhitespaces; - value = [header substringWithRange: - of_range(pos + 1, header.length - pos - 1)]; - value = value.stringByDeletingEnclosingWhitespaces; + value = [header substringFromIndex: pos + 1] + .stringByDeletingEnclosingWhitespaces; [_clientHeaders setObject: value forKey: name]; } @@ -396,13 +395,13 @@ unsigned long long port; if (pos == OF_NOT_FOUND) @throw [OFInvalidFormatException exception]; - host = [proxy substringWithRange: of_range(0, pos)]; - port = [proxy substringWithRange: of_range(pos + 1, - proxy.length - pos - 1)].unsignedLongLongValue; + host = [proxy substringToIndex: pos]; + port = [proxy substringFromIndex: pos + 1] + .unsignedLongLongValue; if (port > UINT16_MAX) @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host];