@@ -189,12 +189,11 @@ &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, UTF8String, UTF8StringLength); _s->cString[UTF8StringLength] = 0; } @catch (id e) { @@ -231,17 +230,16 @@ switch (of_string_utf8_check(cString, cStringLength, &_s->length)) { case 1: if (encoding == OF_STRING_ENCODING_ASCII) @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; _s->isUTF8 = true; break; case -1: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, cString, cStringLength); _s->cString[cStringLength] = 0; @@ -265,11 +263,11 @@ bytes = of_string_utf8_encode( (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; _s->cStringLength += bytes - 1; _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + 1]; @@ -289,12 +287,11 @@ break; case OF_STRING_ENCODING_WINDOWS_1252: table = of_windows_1252; break; default: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } for (i = j = 0; i < cStringLength; i++) { char buffer[4]; of_unichar_t character; @@ -306,20 +303,18 @@ } character = table[(uint8_t)cString[i]]; if (character == 0xFFFD) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; _s->isUTF8 = true; characterBytes = of_string_utf8_encode(character, buffer); if (characterBytes == 0) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; _s->cStringLength += characterBytes - 1; _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + 1]; @@ -363,12 +358,11 @@ &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } } @catch (id e) { [self release]; @throw e; } @@ -433,12 +427,11 @@ memcpy(_s->cString + j, buffer, len); j += len; break; default: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } } _s->cString[j] = '\0'; _s->cStringLength = j; @@ -488,27 +481,26 @@ (swap ? OF_BSWAP16(string[i]) : string[i]); size_t len; /* Missing high surrogate */ if ((character & 0xFC00) == 0xDC00) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; if ((character & 0xFC00) == 0xD800) { of_char16_t nextCharacter; if (length <= i + 1) @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; nextCharacter = (swap ? OF_BSWAP16(string[i + 1]) : string[i + 1]); if ((nextCharacter & 0xFC00) != 0xDC00) @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + exception]; character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; @@ -529,12 +521,11 @@ memcpy(_s->cString + j, buffer, len); j += len; break; default: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } } _s->cString[j] = '\0'; _s->cStringLength = j; @@ -596,12 +587,11 @@ memcpy(_s->cString + j, buffer, len); j += len; break; default: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } } _s->cString[j] = '\0'; _s->cStringLength = j; @@ -628,20 +618,17 @@ @try { char *tmp; int cStringLength; if (format == nil) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; _s = &_storage; if ((cStringLength = of_vasprintf(&tmp, [format UTF8String], arguments)) == -1) - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; _s->cStringLength = cStringLength; @try { switch (of_string_utf8_check(tmp, cStringLength, @@ -648,12 +635,11 @@ &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; } _s->cString = [self allocMemoryWithSize: cStringLength + 1]; memcpy(_s->cString, tmp, cStringLength + 1); @@ -745,17 +731,15 @@ encoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: if (_s->isUTF8) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: if (_s->cStringLength + 1 > maxLength) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; memcpy(cString, _s->cString, _s->cStringLength + 1); return _s->cStringLength; default: @@ -768,12 +752,11 @@ - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: if (_s->isUTF8) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: return _s->cString; default: return [super cStringWithEncoding: encoding]; @@ -842,13 +825,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; otherCStringLength = [otherString UTF8StringLength]; minimumCStringLength = (_s->cStringLength > otherCStringLength ? otherCStringLength : _s->cStringLength); @@ -876,13 +857,11 @@ if (otherString == self) return OF_ORDERED_SAME; if (![otherString isKindOfClass: [OFString class]]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; otherCString = [otherString UTF8String]; otherCStringLength = [otherString UTF8StringLength]; if (!_s->isUTF8) { @@ -914,12 +893,11 @@ _s->cStringLength - i, &c1); l2 = of_string_utf8_decode(otherCString + j, otherCStringLength - j, &c2); if (l1 == 0 || l2 == 0 || c1 > 0x10FFFF || c2 > 0x10FFFF) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; if (c1 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) { of_unichar_t tc = of_unicode_casefolding_table[c1 >> 8][c1 & 0xFF]; @@ -966,12 +944,11 @@ of_unichar_t c; size_t length; if ((length = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c)) == 0) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; OF_HASH_ADD(hash, (c & 0xFF0000) >> 16); OF_HASH_ADD(hash, (c & 0x00FF00) >> 8); OF_HASH_ADD(hash, c & 0x0000FF); @@ -989,22 +966,21 @@ - (of_unichar_t)characterAtIndex: (size_t)index { of_unichar_t character; if (index >= _s->length) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (!_s->isUTF8) return _s->cString[index]; index = of_string_utf8_get_position(_s->cString, index, _s->cStringLength); if (!of_string_utf8_decode(_s->cString + index, _s->cStringLength - index, &character)) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; return character; } - (void)getCharacters: (of_unichar_t*)buffer @@ -1014,11 +990,11 @@ void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; memcpy(buffer, characters + range.location, range.length * sizeof(of_unichar_t)); objc_autoreleasePoolPop(pool); @@ -1032,11 +1008,11 @@ size_t i, cStringLength = [string UTF8StringLength]; size_t rangeLocation, rangeLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { rangeLocation = of_string_utf8_get_position( _s->cString, range.location, _s->cStringLength); rangeLength = of_string_utf8_get_position( @@ -1106,11 +1082,11 @@ { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = of_string_utf8_get_position(_s->cString, start, _s->cStringLength); end = of_string_utf8_get_position(_s->cString, end, @@ -1324,12 +1300,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; ret[j++] = c; i += cLen; } @@ -1353,12 +1328,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) - @throw [OFInvalidEncodingException - exceptionWithClass: [self class]]; + @throw [OFInvalidEncodingException exception]; if (byteOrder != OF_BYTE_ORDER_NATIVE) ret[j++] = OF_BSWAP32(c); else ret[j++] = c;