@@ -884,17 +884,15 @@ OFFile *file; if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &st) == -1) @throw [OFOpenFileFailedException - exceptionWithClass: [self class] - path: path - mode: @"rb"]; + exceptionWithPath: path + mode: @"rb"]; if (st.st_size > SIZE_MAX) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @try { @@ -958,13 +956,12 @@ request = [OFHTTPRequest requestWithURL: URL]; reply = [client performRequest: request]; if ([reply statusCode] != 200) @throw [OFHTTPRequestFailedException - exceptionWithClass: [request class] - request: request - reply: reply]; + exceptionWithRequest: request + reply: reply]; headers = [reply headers]; if (encoding == OF_STRING_ENCODING_AUTODETECT && (contentType = [headers objectForKey: @"Content-Type"]) != nil) { @@ -985,18 +982,17 @@ data = [reply readDataArrayTillEndOfStream]; if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) if ([data count] != (size_t)[contentLength decimalValue]) - @throw [OFTruncatedDataException - exceptionWithClass: [self class]]; + @throw [OFTruncatedDataException exception]; self = [[c alloc] initWithCString: (char*)[data items] encoding: encoding length: [data count]]; #else - @throw [OFUnsupportedProtocolException exceptionWithClass: c]; + @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; #endif objc_autoreleasePoolPop(pool); return self; @@ -1006,24 +1002,18 @@ { @try { void *pool = objc_autoreleasePoolPush(); if (![[element namespace] isEqual: OF_SERIALIZATION_NS]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; if ([self isKindOfClass: [OFMutableString class]]) { if (![[element name] isEqual: @"OFMutableString"]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; } else { if (![[element name] isEqual: @"OFString"]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; } self = [self initWithString: [element stringValue]]; objc_autoreleasePoolPop(pool); @@ -1054,12 +1044,11 @@ /* * Check for one more than the current index, as we * need one for the terminating zero. */ if (j + len >= maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; switch (len) { case 1: cString[j++] = buffer[0]; @@ -1070,54 +1059,48 @@ memcpy(cString + j, buffer, len); j += len; break; default: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } } cString[j] = '\0'; return j; case OF_STRING_ENCODING_ASCII: if (length + 1 > maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0x80) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; cString[i] = (char)characters[i]; } cString[i] = '\0'; return length; case OF_STRING_ENCODING_ISO_8859_1: if (length + 1 > maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0xFF) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; cString[i] = (uint8_t)characters[i]; } cString[i] = '\0'; return length; case OF_STRING_ENCODING_ISO_8859_15: if (length + 1 > maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { of_unichar_t c = characters[i]; switch (c) { @@ -1127,12 +1110,11 @@ case 0xB4: case 0xB8: case 0xBC: case 0xBD: case 0xBE: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } if OF_UNLIKELY (c > 0xFF) { switch (c) { case 0x20AC: @@ -1159,11 +1141,11 @@ case 0x178: cString[i] = 0xBE; break; default: @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; } } else cString[i] = (uint8_t)c; } @@ -1170,19 +1152,17 @@ cString[i] = '\0'; return length; case OF_STRING_ENCODING_WINDOWS_1252: if (length + 1 > maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { of_unichar_t c = characters[i]; if OF_UNLIKELY (c >= 0x80 && c <= 0x9F) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; if OF_UNLIKELY (c > 0xFF) { switch (c) { case 0x20AC: cString[i] = 0x80; @@ -1265,23 +1245,22 @@ case 0x178: cString[i] = 0x9F; break; default: @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; } } else cString[i] = (uint8_t)c; } cString[i] = '\0'; return length; default: - @throw [OFNotImplementedException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; } } - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { @@ -1317,13 +1296,12 @@ maxLength: length + 1 encoding: encoding]; break; default: - @throw [OFNotImplementedException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; } return cString; } @@ -1352,12 +1330,11 @@ char buffer[4]; size_t len = of_string_utf8_encode(characters[i], buffer); if (len == 0) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; UTF8StringLength += len; } return UTF8StringLength; @@ -1365,13 +1342,12 @@ case OF_STRING_ENCODING_ISO_8859_1: case OF_STRING_ENCODING_ISO_8859_15: case OF_STRING_ENCODING_WINDOWS_1252: return [self length]; default: - @throw [OFNotImplementedException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; } } - (size_t)UTF8StringLength { @@ -1447,13 +1423,11 @@ if (object == self) return OF_ORDERED_SAME; if (![object isKindOfClass: [OFString class]]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; otherString = (OFString*)object; minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); @@ -1658,11 +1632,11 @@ [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; [data addItems: [self UTF8String] count: length]; return data; @@ -1697,21 +1671,20 @@ if (searchLength > range.length) return of_range(OF_NOT_FOUND, 0); if (range.length > SIZE_MAX / sizeof(of_unichar_t)) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = [string characters]; characters = malloc(range.length * sizeof(of_unichar_t)); if (characters == NULL) - @throw [OFOutOfMemoryException - exceptionWithClass: [self class] - requestedSize: range.length * sizeof(of_unichar_t)]; + @throw [OFOutOfMemoryException exceptionWithRequestedSize: + range.length * sizeof(of_unichar_t)]; @try { [self getCharacters: characters inRange: range]; @@ -1782,12 +1755,11 @@ void *pool; OFString *ret; if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); ret = [[OFString alloc] initWithCharacters: [self characters] + range.location length: range.length]; @@ -2244,29 +2216,26 @@ for (; i < length; i++) { if (expectWhitespace) { if (characters[i] != ' ' && characters[i] != '\t' && characters[i] != '\n' && characters[i] != '\r' && characters[i] != '\f') - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; continue; } if (characters[i] >= '0' && characters[i] <= '9') { if (INTMAX_MAX / 10 < value || INTMAX_MAX - value * 10 < characters[i] - '0') - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; value = (value * 10) + (characters[i] - '0'); } else if (characters[i] == ' ' || characters[i] == '\t' || characters[i] == '\n' || characters[i] == '\r' || characters[i] == '\f') expectWhitespace = true; else - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; } if (characters[0] == '-') value *= -1; @@ -2306,12 +2275,11 @@ if (expectWhitespace) { if (characters[i] != ' ' && characters[i] != '\t' && characters[i] != '\n' && characters[i] != '\r' && characters[i] != '\f') - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; continue; } if (characters[i] >= '0' && characters[i] <= '9') { newValue = (value << 4) | (characters[i] - '0'); @@ -2326,23 +2294,20 @@ characters[i] == '\t' || characters[i] == '\n' || characters[i] == '\r' || characters[i] == '\f') { expectWhitespace = true; continue; } else - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; if (newValue < value) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; value = newValue; } if (!foundValue) - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } @@ -2364,12 +2329,11 @@ if (endPointer != NULL) for (; *endPointer != '\0'; endPointer++) if (*endPointer != ' ' && *endPointer != '\t' && *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } @@ -2391,12 +2355,11 @@ if (endPointer != NULL) for (; *endPointer != '\0'; endPointer++) if (*endPointer != ' ' && *endPointer != '\t' && *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } @@ -2438,12 +2401,11 @@ for (i = 0; i < length; i++) { of_unichar_t c = characters[i]; if (c > 0x10FFFF) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; if (swap) { if (c > 0xFFFF) { c -= 0x10000; ret[j++] = OF_BSWAP16(0xD800 | (c >> 10));