Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -82,51 +82,25 @@ - initWithString: (OFString*)string { return (id)[[OFMutableString_UTF8 alloc] initWithString: string]; } -- initWithUnicodeString: (const of_unichar_t*)string -{ - return (id)[[OFMutableString_UTF8 alloc] initWithUnicodeString: string]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return (id)[[OFMutableString_UTF8 alloc] - initWithUnicodeString: string - byteOrder: byteOrder]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length -{ - return (id)[[OFMutableString_UTF8 alloc] initWithUnicodeString: string - length: length]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length -{ - return (id)[[OFMutableString_UTF8 alloc] - initWithUnicodeString: string - byteOrder: byteOrder - length: length]; -} - -- initWithUTF16String: (const uint16_t*)string -{ - return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string]; -} - -- initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return (id)[[OFMutableString_UTF8 alloc] - initWithUTF16String: string - byteOrder: byteOrder]; +- initWithCharacters: (const of_unichar_t*)characters + length: (size_t)length +{ + return (id)[[OFMutableString_UTF8 alloc] initWithCharacters: characters + length: length]; +} + +- initWithCharacters: (const of_unichar_t*)characters + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder +{ + return (id)[[OFMutableString_UTF8 alloc] + initWithCharacters: characters + length: length + byteOrder: byteOrder]; } - initWithUTF16String: (const uint16_t*)string length: (size_t)length { @@ -133,17 +107,17 @@ return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string length: length]; } - initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string - byteOrder: byteOrder - length: length]; + length: length + byteOrder: byteOrder]; } - initWithFormat: (OFConstantString*)format, ... { id ret; @@ -259,18 +233,18 @@ wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *string = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t i, length = [self length]; BOOL isStart = YES; for (i = 0; i < length; i++) { const of_unichar_t *const *table; size_t tableSize; - of_unichar_t c = string[i]; + of_unichar_t c = characters[i]; if (isStart) { table = startTable; tableSize = middleTableSize; } else { @@ -302,12 +276,12 @@ atIndex: (size_t)index { void *pool = objc_autoreleasePoolPush(); OFString *string; - string = [OFString stringWithUnicodeString: &character - length: 1]; + string = [OFString stringWithCharacters: &character + length: 1]; [self replaceCharactersInRange: of_range(index, 1) withString: string]; objc_autoreleasePoolPop(pool); @@ -473,12 +447,12 @@ withString: (OFString*)replacement options: (int)options range: (of_range_t)range { void *pool = objc_autoreleasePoolPush(), *pool2; - const of_unichar_t *unicodeString; - const of_unichar_t *searchString = [string unicodeString]; + const of_unichar_t *characters; + const of_unichar_t *searchCharacters = [string characters]; size_t searchLength = [string length]; size_t replacementLength = [replacement length]; size_t i; if (range.length > SIZE_MAX - range.location || @@ -489,14 +463,14 @@ objc_autoreleasePoolPop(pool); return; } pool2 = objc_autoreleasePoolPush(); - unicodeString = [self unicodeString]; + characters = [self characters]; for (i = range.location; i <= range.length - searchLength; i++) { - if (memcmp(unicodeString + i, searchString, + if (memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t))) continue; [self replaceCharactersInRange: of_range(i, searchLength) withString: replacement]; @@ -507,11 +481,11 @@ i += replacementLength - 1; objc_autoreleasePoolPop(pool2); pool2 = objc_autoreleasePoolPush(); - unicodeString = [self unicodeString]; + characters = [self characters]; } objc_autoreleasePoolPop(pool); } Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -135,71 +135,33 @@ * @param string A string to initialize the OFString with * @return A new autoreleased OFString */ + (instancetype)stringWithString: (OFString*)string; -/*! - * @brief Creates a new OFString from a unicode string. - * - * @param string The unicode string - * @return A new autoreleased OFString - */ -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string; - -/*! - * @brief Creates a new OFString from a unicode string, assuming the specified - * byte order if no BOM is found. - * - * @param string The unicode string - * @param byteOrder The byte order to assume if there is no BOM - * @return A new autoreleased OFString - */ -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder; - /*! * @brief Creates a new OFString from a unicode string with the specified * length. * - * @param string The unicode string - * @param length The length of the unicode string + * @param characters An array of unicode characters + * @param length The length of the unicode character array * @return A new autoreleased OFString */ -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length; ++ (instancetype)stringWithCharacters: (const of_unichar_t*)characters + length: (size_t)length; /*! * @brief Creates a new OFString from a unicode string with the specified * length, assuming the specified byte order if no BOM is found. * - * @param string The unicode string - * @param byteOrder The byte order to assume if there is no BOM - * @param length The length of the unicode string - * @return A new autoreleased OFString - */ -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length; - -/*! - * @brief Creates a new OFString from a big endian UTF-16 encoded string. - * - * @param string The UTF-16 string - * @return A new autoreleased OFString - */ -+ (instancetype)stringWithUTF16String: (const uint16_t*)string; - -/*! - * @brief Creates a new OFString from a UTF-16 encoded string, assuming the - * specified byte order if no BOM is found. - * - * @param string The UTF-16 string - * @param byteOrder The byte order to assume if there is no BOM - * @return A new autoreleased OFString - */ -+ (instancetype)stringWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder; + * @param characters An array of unicode characters + * @param length The length of the unicode character array + * @param byteOrder The byte order to assume if there is no BOM + * @return A new autoreleased OFString + */ ++ (instancetype)stringWithCharacters: (const of_unichar_t*)characters + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a big endian UTF-16 encoded string with * the specified length. * @@ -214,17 +176,17 @@ * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length, assuming the specified byte order if no BOM is * found. * * @param string The UTF-16 string - * @param byteOrder The byte order to assume if there is no BOM * @param length The length of the unicode string + * @param byteOrder The byte order to assume if there is no BOM * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length; + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a format string. * * See printf for the format syntax. As an addition, %@ is available as format @@ -352,72 +314,34 @@ * @param string A string to initialize the OFString with * @return An initialized OFString */ - initWithString: (OFString*)string; -/*! - * @brief Initializes an already allocated OFString with a unicode string. - * - * @param string The unicode string - * @return An initialized OFString - */ -- initWithUnicodeString: (const of_unichar_t*)string; - -/*! - * @brief Initializes an already allocated OFString with a unicode string, - * assuming the specified byte order if no BOM is found. - * - * @param string The unicode string - * @param byteOrder The byte order to assume if there is no BOM - * @return An initialized OFString - */ -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder; - /*! * @brief Initializes an already allocated OFString with a unicode string with * the specified length. * - * @param string The unicode string - * @param length The length of the unicode string + * @param characters An array of unicode characters + * @param length The length of the unicode character array * @return An initialized OFString */ -- initWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length; +- initWithCharacters: (const of_unichar_t*)characters + length: (size_t)length; /*! * @brief Initializes an already allocated OFString with a unicode string with * the specified length, assuming the specified byte order if no BOM is * found. * - * @param string The unicode string - * @param byteOrder The byte order to assume if there is no BOM - * @param length The length of the unicode string - * @return An initialized OFString - */ -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length; - -/*! - * @brief Initializes an already allocated OFString with a UTF-16 string. - * - * @param string The UTF-16 string - * @return An initialized OFString - */ -- initWithUTF16String: (const uint16_t*)string; - -/*! - * @brief Initializes an already allocated OFString with a UTF-16 string, - * assuming the specified byte order if no BOM is found. - * - * @param string The UTF-16 string - * @param byteOrder The byte order to assume if there is no BOM - * @return An initialized OFString - */ -- initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder; + * @param characters An array of unicode characters + * @param length The length of the unicode character array + * @param byteOrder The byte order to assume if there is no BOM + * @return An initialized OFString + */ +- initWithCharacters: (const of_unichar_t*)characters + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length. * @@ -432,17 +356,17 @@ * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length, assuming the specified byte order if no BOM is * found. * * @param string The UTF-16 string - * @param byteOrder The byte order to assume if there is no BOM * @param length The length of the UTF-16 string + * @param byteOrder The byte order to assume if there is no BOM * @return An initialized OFString */ - initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length; + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a format string. * * See printf for the format syntax. As an addition, %@ is available as format @@ -907,11 +831,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @return The string as an array of Unicode characters */ -- (const of_unichar_t*)unicodeString OF_RETURNS_INNER_POINTER; +- (const of_unichar_t*)characters OF_RETURNS_INNER_POINTER; /*! * @brief Returns the string in big endian UTF-16 encoding. * * The result is valid until the autorelease pool is released. If you want to @@ -956,10 +880,8 @@ #ifdef __cplusplus extern "C" { #endif extern size_t of_string_utf8_encode(of_unichar_t, char*); extern size_t of_string_utf8_decode(const char*, size_t, of_unichar_t*); -extern size_t of_string_utf16_length(const uint16_t*); -extern size_t of_string_unicode_length(const of_unichar_t*); #ifdef __cplusplus } #endif Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -140,32 +140,10 @@ } return 0; } -size_t -of_string_unicode_length(const of_unichar_t *string) -{ - const of_unichar_t *string_ = string; - - while (*string_ != 0) - string_++; - - return (size_t)(string_ - string); -} - -size_t -of_string_utf16_length(const uint16_t *string) -{ - const uint16_t *string_ = string; - - while (*string_ != 0) - string_++; - - return (size_t)(string_ - string); -} - static OFString* standardize_path(OFArray *components, OFString *currentDirectory, OFString *parentDirectory, OFString *joinString) { void *pool = objc_autoreleasePoolPush(); @@ -305,48 +283,24 @@ - initWithString: (OFString*)string { return (id)[[OFString_UTF8 alloc] initWithString: string]; } -- initWithUnicodeString: (const of_unichar_t*)string -{ - return (id)[[OFString_UTF8 alloc] initWithUnicodeString: string]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return (id)[[OFString_UTF8 alloc] initWithUnicodeString: string - byteOrder: byteOrder]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length -{ - return (id)[[OFString_UTF8 alloc] initWithUnicodeString: string - length: length]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length -{ - return (id)[[OFString_UTF8 alloc] initWithUnicodeString: string - byteOrder: byteOrder - length: length]; -} - -- initWithUTF16String: (const uint16_t*)string -{ - return (id)[[OFString_UTF8 alloc] initWithUTF16String: string]; -} - -- initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return (id)[[OFString_UTF8 alloc] initWithUTF16String: string - byteOrder: byteOrder]; +- initWithCharacters: (const of_unichar_t*)string + length: (size_t)length +{ + return (id)[[OFString_UTF8 alloc] initWithCharacters: string + length: length]; +} + +- initWithCharacters: (const of_unichar_t*)string + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder +{ + return (id)[[OFString_UTF8 alloc] initWithCharacters: string + length: length + byteOrder: byteOrder]; } - initWithUTF16String: (const uint16_t*)string length: (size_t)length { @@ -353,16 +307,16 @@ return (id)[[OFString_UTF8 alloc] initWithUTF16String: string length: length]; } - initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string - byteOrder: byteOrder - length: length]; + length: length + byteOrder: byteOrder]; } - initWithFormat: (OFConstantString*)format, ... { id ret; @@ -516,48 +470,24 @@ + (instancetype)stringWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; } -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string -{ - return [[[self alloc] initWithUnicodeString: string] autorelease]; -} - -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return [[[self alloc] initWithUnicodeString: string - byteOrder: byteOrder] autorelease]; -} - -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length -{ - return [[[self alloc] initWithUnicodeString: string - length: length] autorelease]; -} - -+ (instancetype)stringWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length -{ - return [[[self alloc] initWithUnicodeString: string - byteOrder: byteOrder - length: length] autorelease]; -} - -+ (instancetype)stringWithUTF16String: (const uint16_t*)string -{ - return [[[self alloc] initWithUTF16String: string] autorelease]; -} - -+ (instancetype)stringWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return [[[self alloc] initWithUTF16String: string - byteOrder: byteOrder] autorelease]; ++ (instancetype)stringWithCharacters: (const of_unichar_t*)string + length: (size_t)length +{ + return [[[self alloc] initWithCharacters: string + length: length] autorelease]; +} + ++ (instancetype)stringWithCharacters: (const of_unichar_t*)string + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder +{ + return [[[self alloc] initWithCharacters: string + length: length + byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF16String: (const uint16_t*)string length: (size_t)length { @@ -564,16 +494,16 @@ return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF16String: string - byteOrder: byteOrder - length: length] autorelease]; + length: length + byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithFormat: (OFConstantString*)format, ... { id ret; @@ -690,36 +620,21 @@ [self release]; @throw e; } } -- initWithUnicodeString: (const of_unichar_t*)string -{ - return [self initWithUnicodeString: string - byteOrder: OF_BYTE_ORDER_NATIVE - length: of_string_unicode_length(string)]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return [self initWithUnicodeString: string - byteOrder: byteOrder - length: of_string_unicode_length(string)]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - length: (size_t)length -{ - return [self initWithUnicodeString: string - byteOrder: OF_BYTE_ORDER_NATIVE - length: length]; -} - -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length +- initWithCharacters: (const of_unichar_t*)string + length: (size_t)length +{ + return [self initWithCharacters: string + length: length + byteOrder: OF_BYTE_ORDER_NATIVE]; +} + +- initWithCharacters: (const of_unichar_t*)string + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { @@ -727,35 +642,20 @@ @throw e; } } - initWithUTF16String: (const uint16_t*)string + length: (size_t)length { return [self initWithUTF16String: string - byteOrder: OF_BYTE_ORDER_BIG_ENDIAN - length: of_string_utf16_length(string)]; -} - -- initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder -{ - return [self initWithUTF16String: string - byteOrder: byteOrder - length: of_string_utf16_length(string)]; + length: length + byteOrder: OF_BYTE_ORDER_BIG_ENDIAN]; } - initWithUTF16String: (const uint16_t*)string length: (size_t)length -{ - return [self initWithUTF16String: string - byteOrder: OF_BYTE_ORDER_BIG_ENDIAN - length: length]; -} - -- initWithUTF16String: (const uint16_t*)string byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { @@ -963,11 +863,11 @@ return self; } - (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding { - const of_unichar_t *unicodeString = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t i, length = [self length]; OFObject *object = [[[OFObject alloc] init] autorelease]; char *cString; switch (encoding) { @@ -977,11 +877,11 @@ cString = [object allocMemoryWithSize: (length * 4) + 1]; cStringLength = length; for (i = 0; i < length; i++) { char buffer[4]; - size_t len = of_string_utf8_encode(unicodeString[i], + size_t len = of_string_utf8_encode(characters[i], buffer); switch (len) { case 1: cString[j++] = buffer[0]; @@ -1027,29 +927,29 @@ break; case OF_STRING_ENCODING_ASCII: cString = [object allocMemoryWithSize: length + 1]; for (i = 0; i < length; i++) { - if (unicodeString[i] > 0x80) + if (characters[i] > 0x80) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - cString[i] = (char)unicodeString[i]; + cString[i] = (char)characters[i]; } cString[i] = '\0'; break; case OF_STRING_ENCODING_ISO_8859_1: cString = [object allocMemoryWithSize: length + 1]; for (i = 0; i < length; i++) { - if (unicodeString[i] > 0xFF) + if (characters[i] > 0xFF) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - cString[i] = (uint8_t)unicodeString[i]; + cString[i] = (uint8_t)characters[i]; } cString[i] = '\0'; break; @@ -1075,19 +975,19 @@ - (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_UTF_8:; - const of_unichar_t *unicodeString; + const of_unichar_t *characters; size_t i, length, UTF8StringLength = 0; - unicodeString = [self unicodeString]; + characters = [self characters]; length = [self length]; for (i = 0; i < length; i++) { char buffer[4]; - size_t len = of_string_utf8_encode(unicodeString[i], + size_t len = of_string_utf8_encode(characters[i], buffer); if (len == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -1128,11 +1028,11 @@ - (BOOL)isEqual: (id)object { void *pool; OFString *otherString; - const of_unichar_t *unicodeString, *otherUnicodeString; + const of_unichar_t *characters, *otherCharacters; size_t length; if (object == self) return YES; @@ -1145,14 +1045,14 @@ if ([otherString length] != length) return NO; pool = objc_autoreleasePoolPush(); - unicodeString = [self unicodeString]; - otherUnicodeString = [otherString unicodeString]; + characters = [self characters]; + otherCharacters = [otherString characters]; - if (memcmp(unicodeString, otherUnicodeString, + if (memcmp(characters, otherCharacters, length * sizeof(of_unichar_t))) { objc_autoreleasePoolPop(pool); return NO; } @@ -1173,11 +1073,11 @@ - (of_comparison_result_t)compare: (id )object { void *pool; OFString *otherString; - const of_unichar_t *unicodeString, *otherUnicodeString; + const of_unichar_t *characters, *otherCharacters; size_t i, minimumLength; if (object == self) return OF_ORDERED_SAME; @@ -1190,20 +1090,20 @@ minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); pool = objc_autoreleasePoolPush(); - unicodeString = [self unicodeString]; - otherUnicodeString = [otherString unicodeString]; + characters = [self characters]; + otherCharacters = [otherString characters]; for (i = 0; i < minimumLength; i++) { - if (unicodeString[i] > otherUnicodeString[i]) { + if (characters[i] > otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } - if (unicodeString[i] < otherUnicodeString[i]) { + if (characters[i] < otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OF_ORDERED_ASCENDING; } } @@ -1218,26 +1118,26 @@ } - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString { void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *string, *otherUnicodeString; + const of_unichar_t *characters, *otherCharacters; size_t i, length, otherLength, minimumLength; if (otherString == self) return OF_ORDERED_SAME; - string = [self unicodeString]; - otherUnicodeString = [otherString unicodeString]; + characters = [self characters]; + otherCharacters = [otherString characters]; length = [self length]; otherLength = [otherString length]; minimumLength = (length > otherLength ? otherLength : length); for (i = 0; i < minimumLength; i++) { - of_unichar_t c = string[i]; - of_unichar_t oc = otherUnicodeString[i]; + of_unichar_t c = characters[i]; + of_unichar_t oc = otherCharacters[i]; if (c >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) { of_unichar_t tc = of_unicode_casefolding_table[c >> 8][c & 0xFF]; @@ -1273,18 +1173,18 @@ return OF_ORDERED_SAME; } - (uint32_t)hash { - const of_unichar_t *unicodeString = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t i, length = [self length]; uint32_t hash; OF_HASH_INIT(hash); for (i = 0; i < length; i++) { - const of_unichar_t c = unicodeString[i]; + const of_unichar_t c = characters[i]; OF_HASH_ADD(hash, (c & 0xFF0000) >> 16); OF_HASH_ADD(hash, (c & 0x00FF00) >> 8); OF_HASH_ADD(hash, c & 0x0000FF); } @@ -1367,12 +1267,12 @@ - (of_range_t)rangeOfString: (OFString*)string options: (int)options range: (of_range_t)range { void *pool; - const of_unichar_t *searchString; - of_unichar_t *unicodeString; + const of_unichar_t *searchCharacters; + of_unichar_t *characters; size_t i, searchLength; if ((searchLength = [string length]) == 0) return of_range(0, 0); @@ -1382,25 +1282,25 @@ if (range.length > SIZE_MAX / sizeof(of_unichar_t)) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; pool = objc_autoreleasePoolPush(); - searchString = [string unicodeString]; - unicodeString = malloc(range.length * sizeof(of_unichar_t)); + searchCharacters = [string characters]; + characters = malloc(range.length * sizeof(of_unichar_t)); - if (unicodeString == NULL) + if (characters == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: range.length * sizeof(of_unichar_t)]; @try { - [self getCharacters: unicodeString + [self getCharacters: characters inRange: range]; if (options & OF_STRING_SEARCH_BACKWARDS) { for (i = range.length - searchLength;; i--) { - if (!memcmp(unicodeString + i, searchString, + if (!memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t))) { objc_autoreleasePoolPop(pool); return of_range(range.location + i, searchLength); } @@ -1409,20 +1309,20 @@ if (i == 0) break; } } else { for (i = 0; i <= range.length - searchLength; i++) { - if (!memcmp(unicodeString + i, searchString, + if (!memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t))) { objc_autoreleasePoolPop(pool); return of_range(range.location + i, searchLength); } } } } @finally { - free(unicodeString); + free(characters); } objc_autoreleasePoolPop(pool); return of_range(OF_NOT_FOUND, 0); @@ -1429,11 +1329,11 @@ } - (BOOL)containsString: (OFString*)string { void *pool; - const of_unichar_t *unicodeString, *searchString; + const of_unichar_t *characters, *searchCharacters; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return YES; @@ -1440,15 +1340,15 @@ if (searchLength > (length = [self length])) return NO; pool = objc_autoreleasePoolPush(); - unicodeString = [self unicodeString]; - searchString = [string unicodeString]; + characters = [self characters]; + searchCharacters = [string characters]; for (i = 0; i <= length - searchLength; i++) { - if (!memcmp(unicodeString + i, searchString, + if (!memcmp(characters + i, searchCharacters, searchLength * sizeof(of_unichar_t))) { objc_autoreleasePoolPop(pool); return YES; } } @@ -1468,12 +1368,12 @@ @throw [OFOutOfRangeException exceptionWithClass: [self class]]; pool = objc_autoreleasePoolPush(); ret = [[OFString alloc] - initWithUnicodeString: [self unicodeString] + range.location - length: range.length]; + initWithCharacters: [self characters] + range.location + length: range.length]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -1629,11 +1529,11 @@ } - (BOOL)hasPrefix: (OFString*)prefix { of_unichar_t *tmp; - const of_unichar_t *prefixString; + const of_unichar_t *prefixCharacters; size_t prefixLength; int compare; if ((prefixLength = [prefix length]) > [self length]) return NO; @@ -1644,12 +1544,12 @@ void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; - prefixString = [prefix unicodeString]; - compare = memcmp(tmp, prefixString, + prefixCharacters = [prefix characters]; + compare = memcmp(tmp, prefixCharacters, prefixLength * sizeof(of_unichar_t)); objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; @@ -1659,11 +1559,11 @@ } - (BOOL)hasSuffix: (OFString*)suffix { of_unichar_t *tmp; - const of_unichar_t *suffixString; + const of_unichar_t *suffixCharacters; size_t length, suffixLength; int compare; if ((suffixLength = [suffix length]) > [self length]) return NO; @@ -1677,12 +1577,12 @@ [self getCharacters: tmp inRange: of_range(length - suffixLength, suffixLength)]; - suffixString = [suffix unicodeString]; - compare = memcmp(tmp, suffixString, + suffixCharacters = [suffix characters]; + compare = memcmp(tmp, suffixCharacters, suffixLength * sizeof(of_unichar_t)); objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; @@ -1700,21 +1600,21 @@ - (OFArray*)componentsSeparatedByString: (OFString*)delimiter options: (int)options { void *pool; OFMutableArray *array = [OFMutableArray array]; - const of_unichar_t *string, *delimiterString; + const of_unichar_t *characters, *delimiterCharacters; BOOL skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t length = [self length]; size_t delimiterLength = [delimiter length]; size_t i, last; OFString *component; pool = objc_autoreleasePoolPush(); - string = [self unicodeString]; - delimiterString = [delimiter unicodeString]; + characters = [self characters]; + delimiterCharacters = [delimiter characters]; if (delimiterLength > length) { [array addObject: [[self copy] autorelease]]; [array makeImmutable]; @@ -1722,11 +1622,11 @@ return array; } for (i = 0, last = 0; i <= length - delimiterLength; i++) { - if (memcmp(string + i, delimiterString, + if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(of_unichar_t))) continue; component = [self substringWithRange: of_range(last, i - last)]; if (!skipEmpty || ![component isEqual: @""]) @@ -1748,34 +1648,34 @@ - (OFArray*)pathComponents { OFMutableArray *ret; void *pool; - const of_unichar_t *string; + const of_unichar_t *characters; size_t i, last = 0, length = [self length]; ret = [OFMutableArray array]; if (length == 0) return ret; pool = objc_autoreleasePoolPush(); - string = [self unicodeString]; + characters = [self characters]; #ifndef _WIN32 - if (string[length - 1] == OF_PATH_DELIMITER) + if (characters[length - 1] == OF_PATH_DELIMITER) #else - if (string[length - 1] == '/' || string[length - 1] == '\\') + if (characters[length - 1] == '/' || characters[length - 1] == '\\') #endif length--; for (i = 0; i < length; i++) { #ifndef _WIN32 - if (string[i] == OF_PATH_DELIMITER) { + if (characters[i] == OF_PATH_DELIMITER) { #else - if (string[i] == '/' || string[i] == '\\') { + if (characters[i] == '/' || characters[i] == '\\') { #endif [ret addObject: [self substringWithRange: of_range(last, i - last)]]; last = i + 1; @@ -1792,33 +1692,33 @@ } - (OFString*)lastPathComponent { void *pool; - const of_unichar_t *string; + const of_unichar_t *characters; size_t length = [self length]; ssize_t i; if (length == 0) return @""; pool = objc_autoreleasePoolPush(); - string = [self unicodeString]; + characters = [self characters]; #ifndef _WIN32 - if (string[length - 1] == OF_PATH_DELIMITER) + if (characters[length - 1] == OF_PATH_DELIMITER) #else - if (string[length - 1] == '/' || string[length - 1] == '\\') + if (characters[length - 1] == '/' || characters[length - 1] == '\\') #endif length--; for (i = length - 1; i >= 0; i--) { #ifndef _WIN32 - if (string[i] == OF_PATH_DELIMITER) { + if (characters[i] == OF_PATH_DELIMITER) { #else - if (string[i] == '/' || string[i] == '\\') { + if (characters[i] == '/' || characters[i] == '\\') { #endif i++; break; } } @@ -1836,24 +1736,24 @@ } - (OFString*)stringByDeletingLastPathComponent { void *pool; - const of_unichar_t *string; + const of_unichar_t *characters; size_t i, length = [self length]; if (length == 0) return @""; pool = objc_autoreleasePoolPush(); - string = [self unicodeString]; + characters = [self characters]; #ifndef _WIN32 - if (string[length - 1] == OF_PATH_DELIMITER) + if (characters[length - 1] == OF_PATH_DELIMITER) #else - if (string[length - 1] == '/' || string[length - 1] == '\\') + if (characters[length - 1] == '/' || characters[length - 1] == '\\') #endif length--; if (length == 0) { objc_autoreleasePoolPop(pool); @@ -1860,23 +1760,23 @@ return [self substringWithRange: of_range(0, 1)]; } for (i = length - 1; i >= 1; i--) { #ifndef _WIN32 - if (string[i] == OF_PATH_DELIMITER) { + if (characters[i] == OF_PATH_DELIMITER) { #else - if (string[i] == '/' || string[i] == '\\') { + if (characters[i] == '/' || characters[i] == '\\') { #endif objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, i)]; } } #ifndef _WIN32 - if (string[0] == OF_PATH_DELIMITER) { + if (characters[0] == OF_PATH_DELIMITER) { #else - if (string[0] == '/' || string[0] == '\\') { + if (characters[0] == '/' || characters[0] == '\\') { #endif objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } @@ -1899,57 +1799,58 @@ } - (intmax_t)decimalValue { void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *string = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t length = [self length]; int i = 0; intmax_t value = 0; BOOL expectWhitespace = NO; - while (*string == ' ' || *string == '\t' || *string == '\n' || - *string == '\r' || *string == '\f') { - string++; + while (length > 0 && (*characters == ' ' || *characters == '\t' || + *characters == '\n' || *characters == '\r' || + *characters == '\f')) { + characters++; length--; } if (length == 0) { objc_autoreleasePoolPop(pool); return 0; } - if (string[0] == '-' || string[0] == '+') + if (characters[0] == '-' || characters[0] == '+') i++; for (; i < length; i++) { if (expectWhitespace) { - if (string[i] != ' ' && string[i] != '\t' && - string[i] != '\n' && string[i] != '\r' && - string[i] != '\f') + if (characters[i] != ' ' && characters[i] != '\t' && + characters[i] != '\n' && characters[i] != '\r' && + characters[i] != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; continue; } - if (string[i] >= '0' && string[i] <= '9') { + if (characters[i] >= '0' && characters[i] <= '9') { if (INTMAX_MAX / 10 < value || - INTMAX_MAX - value * 10 < string[i] - '0') + INTMAX_MAX - value * 10 < characters[i] - '0') @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - value = (value * 10) + (string[i] - '0'); - } else if (string[i] == ' ' || string[i] == '\t' || - string[i] == '\n' || string[i] == '\r' || - string[i] == '\f') + value = (value * 10) + (characters[i] - '0'); + } else if (characters[i] == ' ' || characters[i] == '\t' || + characters[i] == '\n' || characters[i] == '\r' || + characters[i] == '\f') expectWhitespace = YES; else @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } - if (string[0] == '-') + if (characters[0] == '-') value *= -1; objc_autoreleasePoolPop(pool); return value; @@ -1956,56 +1857,57 @@ } - (uintmax_t)hexadecimalValue { void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *string = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t length = [self length]; int i = 0; uintmax_t value = 0; BOOL expectWhitespace = NO, foundValue = NO; - while (*string == ' ' || *string == '\t' || *string == '\n' || - *string == '\r' || *string == '\f') { - string++; + while (length > 0 && (*characters == ' ' || *characters == '\t' || + *characters == '\n' || *characters == '\r' || + *characters == '\f')) { + characters++; length--; } if (length == 0) { objc_autoreleasePoolPop(pool); return 0; } - if (length >= 2 && string[0] == '0' && string[1] == 'x') + if (length >= 2 && characters[0] == '0' && characters[1] == 'x') i = 2; - else if (length >= 1 && (string[0] == 'x' || string[0] == '$')) + else if (length >= 1 && (characters[0] == 'x' || characters[0] == '$')) i = 1; for (; i < length; i++) { uintmax_t newValue; if (expectWhitespace) { - if (string[i] != ' ' && string[i] != '\t' && - string[i] != '\n' && string[i] != '\r' && - string[i] != '\f') + if (characters[i] != ' ' && characters[i] != '\t' && + characters[i] != '\n' && characters[i] != '\r' && + characters[i] != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; continue; } - if (string[i] >= '0' && string[i] <= '9') { - newValue = (value << 4) | (string[i] - '0'); - foundValue = YES; - } else if (string[i] >= 'A' && string[i] <= 'F') { - newValue = (value << 4) | (string[i] - 'A' + 10); - foundValue = YES; - } else if (string[i] >= 'a' && string[i] <= 'f') { - newValue = (value << 4) | (string[i] - 'a' + 10); - foundValue = YES; - } else if (string[i] == 'h' || string[i] == ' ' || - string[i] == '\t' || string[i] == '\n' || - string[i] == '\r' || string[i] == '\f') { + if (characters[i] >= '0' && characters[i] <= '9') { + newValue = (value << 4) | (characters[i] - '0'); + foundValue = YES; + } else if (characters[i] >= 'A' && characters[i] <= 'F') { + newValue = (value << 4) | (characters[i] - 'A' + 10); + foundValue = YES; + } else if (characters[i] >= 'a' && characters[i] <= 'f') { + newValue = (value << 4) | (characters[i] - 'a' + 10); + foundValue = YES; + } else if (characters[i] == 'h' || characters[i] == ' ' || + characters[i] == '\t' || characters[i] == '\n' || + characters[i] == '\r' || characters[i] == '\f') { expectWhitespace = YES; continue; } else @throw [OFInvalidFormatException exceptionWithClass: [self class]]; @@ -2027,19 +1929,19 @@ } - (float)floatValue { void *pool = objc_autoreleasePoolPush(); - const char *cString = [self UTF8String]; + const char *UTF8String = [self UTF8String]; char *endPointer = NULL; float value; - while (*cString == ' ' || *cString == '\t' || *cString == '\n' || - *cString == '\r' || *cString == '\f') - cString++; + while (*UTF8String == ' ' || *UTF8String == '\t' || + *UTF8String == '\n' || *UTF8String == '\r' || *UTF8String == '\f') + UTF8String++; - value = strtof(cString, &endPointer); + value = strtof(UTF8String, &endPointer); /* Check if there are any invalid chars left */ if (endPointer != NULL) for (; *endPointer != '\0'; endPointer++) if (*endPointer != ' ' && *endPointer != '\t' && @@ -2054,19 +1956,19 @@ } - (double)doubleValue { void *pool = objc_autoreleasePoolPush(); - const char *cString = [self UTF8String]; + const char *UTF8String = [self UTF8String]; char *endPointer = NULL; double value; - while (*cString == ' ' || *cString == '\t' || *cString == '\n' || - *cString == '\r' || *cString == '\f') - cString++; + while (*UTF8String == ' ' || *UTF8String == '\t' || + *UTF8String == '\n' || *UTF8String == '\r' || *UTF8String == '\f') + UTF8String++; - value = strtod(cString, &endPointer); + value = strtod(UTF8String, &endPointer); /* Check if there are any invalid chars left */ if (endPointer != NULL) for (; *endPointer != '\0'; endPointer++) if (*endPointer != ' ' && *endPointer != '\t' && @@ -2078,42 +1980,41 @@ objc_autoreleasePoolPop(pool); return value; } -- (const of_unichar_t*)unicodeString +- (const of_unichar_t*)characters { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; of_unichar_t *ret; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) - count: length + 1]; + count: length]; [self getCharacters: ret inRange: of_range(0, length)]; - ret[length] = 0; return ret; } - (const uint16_t*)UTF16String { OFObject *object = [[[OFObject alloc] init] autorelease]; void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *unicodeString = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t length = [self length]; uint16_t *ret; size_t i, j; /* Allocate memory for the worst case */ ret = [object allocMemoryWithSize: sizeof(uint16_t) - count: length * 2 + 1]; + count: length * 2]; j = 0; for (i = 0; i < length; i++) { - of_unichar_t c = unicodeString[i]; + of_unichar_t c = characters[i]; if (c > 0x10FFFF) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -2123,16 +2024,14 @@ ret[j++] = OF_BSWAP16_IF_LE(0xDC00 | (c & 0x3FF)); } else ret[j++] = OF_BSWAP16_IF_LE(c); } - ret[j] = 0; - @try { ret = [object resizeMemory: ret size: sizeof(uint16_t) - count: j + 1]; + count: j]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @@ -2154,33 +2053,33 @@ #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *string = [self unicodeString]; + const of_unichar_t *characters = [self characters]; size_t i, last = 0, length = [self length]; BOOL stop = NO, lastCarriageReturn = NO; for (i = 0; i < length && !stop; i++) { - if (lastCarriageReturn && string[i] == '\n') { + if (lastCarriageReturn && characters[i] == '\n') { lastCarriageReturn = NO; last++; continue; } - if (string[i] == '\n' || string[i] == '\r') { + if (characters[i] == '\n' || characters[i] == '\r') { void *pool2 = objc_autoreleasePoolPush(); block([self substringWithRange: of_range(last, i - last)], &stop); last = i + 1; objc_autoreleasePoolPop(pool2); } - lastCarriageReturn = (string[i] == '\r'); + lastCarriageReturn = (characters[i] == '\r'); } if (!stop) block([self substringWithRange: of_range(last, i - last)], &stop); Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -401,26 +401,26 @@ } return self; } -- initWithUnicodeString: (const of_unichar_t*)string - byteOrder: (of_byte_order_t)byteOrder - length: (size_t)length +- initWithCharacters: (const of_unichar_t*)characters + length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t i, j = 0; BOOL swap = NO; - if (length > 0 && *string == 0xFEFF) { - string++; + if (length > 0 && *characters == 0xFEFF) { + characters++; length--; - } else if (length > 0 && *string == 0xFFFE0000) { + } else if (length > 0 && *characters == 0xFFFE0000) { swap = YES; - string++; + characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; @@ -430,11 +430,11 @@ s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t characterLen = of_string_utf8_encode( - (swap ? OF_BSWAP32(string[i]) : string[i]), + (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); switch (characterLen) { case 1: s->cString[j++] = buffer[0]; @@ -484,12 +484,12 @@ return self; } - initWithUTF16String: (const uint16_t*)string - byteOrder: (of_byte_order_t)byteOrder length: (size_t)length + byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t i, j = 0; @@ -951,17 +951,17 @@ - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); - const of_unichar_t *unicodeString = [self unicodeString]; + 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]]; - memcpy(buffer, unicodeString + range.location, + memcpy(buffer, characters + range.location, range.length * sizeof(of_unichar_t)); objc_autoreleasePoolPop(pool); } @@ -1246,18 +1246,18 @@ length: 1]; return @"."; } -- (const of_unichar_t*)unicodeString +- (const of_unichar_t*)characters { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) - count: s->length + 1]; + count: s->length]; i = j = 0; while (i < s->cStringLength) { of_unichar_t c; @@ -1272,12 +1272,10 @@ ret[j++] = c; i += cLen; } - ret[j] = 0; - return ret; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -38,22 +38,21 @@ static OFString* whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static of_unichar_t ucstr[] = { - 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0 + 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A }; static of_unichar_t sucstr[] = { 0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000, - 0x72000000, 0x3AF00100, 0 + 0x72000000, 0x3AF00100 }; static uint16_t utf16str[] = { - 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 + 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A }; static uint16_t sutf16str[] = { - 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, - 0 + 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC }; @interface EntityHandler: OFObject @end @@ -155,20 +154,28 @@ (s[0] = [OFMutableString stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6]) && [s[0] isEqual: @"foo"]) - TEST(@"+[stringWithUnicodeString:]", - (is = [OFString stringWithUnicodeString: ucstr]) && + TEST(@"+[stringWithCharacters:length:]", + (is = [OFString stringWithCharacters: ucstr + length: sizeof(ucstr) / + sizeof(*ucstr)]) && [is isEqual: @"fööbär🀺"] && - (is = [OFString stringWithUnicodeString: sucstr]) && + (is = [OFString stringWithCharacters: sucstr + length: sizeof(sucstr) / + sizeof(*sucstr)]) && [is isEqual: @"fööbär🀺"]) - TEST(@"+[stringWithUTF16String:]", - (is = [OFString stringWithUTF16String: utf16str]) && + TEST(@"+[stringWithUTF16String:length:]", + (is = [OFString stringWithUTF16String: utf16str + length: sizeof(utf16str) / + sizeof(*utf16str)]) && [is isEqual: @"fööbär🀺"] && - (is = [OFString stringWithUTF16String: sutf16str]) && + (is = [OFString stringWithUTF16String: sutf16str + length: sizeof(sutf16str) / + sizeof(*sutf16str)]) && [is isEqual: @"fööbär🀺"]) TEST(@"+[stringWithContentsOfFile:encoding]", (is = [OFString stringWithContentsOfFile: @"testfile.txt" encoding: OF_STRING_ENCODING_ISO_8859_1]) && @@ -401,12 +408,12 @@ OFOutOfRangeException, [@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" hexadecimalValue]) - TEST(@"-[unicodeString]", (ua = [@"fööbär🀺" unicodeString]) && - !memcmp(ua, ucstr + 1, sizeof(ucstr) - sizeof(of_unichar_t))) + TEST(@"-[characters]", (ua = [@"fööbär🀺" characters]) && + !memcmp(ua, ucstr + 1, sizeof(ucstr) / sizeof(*ucstr))) TEST(@"-[UTF16String]", (u16a = [@"fööbär🀺" UTF16String]) && #ifdef OF_BIG_ENDIAN !memcmp(u16a, utf16str + 1, sizeof(utf16str) - sizeof(uint16_t))) #else