Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -89,61 +89,61 @@ { return (id)[[OFMutableString_UTF8 alloc] initWithCharacters: characters length: length]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string { return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length { return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string length: length]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string byteOrder: byteOrder]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFMutableString_UTF8 alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string { return (id)[[OFMutableString_UTF8 alloc] initWithUTF32String: string]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length { return (id)[[OFMutableString_UTF8 alloc] initWithUTF32String: string length: length]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFMutableString_UTF8 alloc] initWithUTF32String: string byteOrder: byteOrder]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFMutableString_UTF8 alloc] initWithUTF32String: string Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -28,11 +28,18 @@ #import "OFSerialization.h" #import "OFJSONRepresentation.h" @class OFConstantString; -typedef uint32_t of_unichar_t; +#if defined(__cplusplus) && __cplusplus >= 201103L +typedef char16_t of_char16_t; +typedef char32_t of_char32_t; +#else +typedef uint_least16_t of_char16_t; +typedef uint_least32_t of_char32_t; +#endif +typedef of_char32_t of_unichar_t; /*! * @brief The encoding of a string. */ typedef enum of_string_encoding_t { @@ -152,21 +159,21 @@ * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string The UTF-16 string * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF16String: (const uint16_t*)string; ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string; /*! * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF16String: (const uint16_t*)string ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string length: (size_t)length; /*! * @brief Creates a new OFString from a UTF-16 encoded string, assuming the * specified byte order if no BOM is found. @@ -173,11 +180,11 @@ * * @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 ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length, assuming the specified byte order if no BOM is @@ -186,31 +193,31 @@ * @param string The UTF-16 string * @param length The length of 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 ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a UTF-32 encoded string. * * @param string The UTF-32 string * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF32String: (const uint32_t*)string; ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string; /*! * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length. * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length; /*! * @brief Creates a new OFString from a UTF-32 encoded string, assuming the * specified byte order if no BOM is found. @@ -217,11 +224,11 @@ * * @param string The UTF-32 string * @param byteOrder The byte order to assume if there is no BOM * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length, assuming the specified byte order if no BOM is @@ -230,11 +237,11 @@ * @param string The UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no BOM * @return A new autoreleased OFString */ -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Creates a new OFString from a format string. @@ -381,21 +388,21 @@ * @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; +- initWithUTF16String: (const of_char16_t*)string; /*! * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString */ -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length; /*! * @brief Initializes an already allocated OFString with a UTF-16 string, * assuming the specified byte order if no BOM is found. @@ -402,11 +409,11 @@ * * @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 +- initWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length, assuming the specified byte order if no BOM is @@ -415,31 +422,31 @@ * @param string The UTF-16 string * @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 +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a UTF-32 string. * * @param string The UTF-32 string * @return An initialized OFString */ -- initWithUTF32String: (const uint32_t*)string; +- initWithUTF32String: (const of_char32_t*)string; /*! * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @return An initialized OFString */ -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length; /*! * @brief Initializes an already allocated OFString with a UTF-32 string, * assuming the specified byte order if no BOM is found. @@ -446,11 +453,11 @@ * * @param string The UTF-32 string * @param byteOrder The byte order to assume if there is no BOM * @return An initialized OFString */ -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length, assuming the specified byte order if no BOM is @@ -459,11 +466,11 @@ * @param string The UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no BOM * @return An initialized OFString */ -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder; /*! * @brief Initializes an already allocated OFString with a format string. @@ -947,11 +954,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @return The string in UTF-16 encoding with native byte order */ -- (const uint16_t*)UTF16String OF_RETURNS_INNER_POINTER; +- (const of_char16_t*)UTF16String OF_RETURNS_INNER_POINTER; /*! * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to @@ -959,11 +966,11 @@ * copy it. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order */ -- (const uint16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder +- (const of_char16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder OF_RETURNS_INNER_POINTER; /*! * @brief Returns the length of the string in UTF-16 characters. * @@ -978,11 +985,11 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @return The string in UTF-32 encoding with native byte order */ -- (const of_unichar_t*)UTF32String OF_RETURNS_INNER_POINTER; +- (const of_char32_t*)UTF32String OF_RETURNS_INNER_POINTER; /*! * @brief Returns the string in UTF-32 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to @@ -990,11 +997,11 @@ * copy it. * * @param byteOrder The byte order for the UTF-32 encoding * @return The string in UTF-32 encoding with the specified byte order */ -- (const of_unichar_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder +- (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder OF_RETURNS_INNER_POINTER; /*! * @brief Writes the string into the specified file using UTF-8 encoding. * @@ -1029,10 +1036,10 @@ #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_utf32_length(const uint32_t*); +extern size_t of_string_utf16_length(const of_char16_t*); +extern size_t of_string_utf32_length(const of_char32_t*); #ifdef __cplusplus } #endif Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -141,11 +141,11 @@ return 0; } size_t -of_string_utf16_length(const uint16_t *string) +of_string_utf16_length(const of_char16_t *string) { size_t length = 0; while (*string++ != 0) length++; @@ -152,11 +152,11 @@ return length; } size_t -of_string_utf32_length(const uint32_t *string) +of_string_utf32_length(const of_char32_t *string) { size_t length = 0; while (*string++ != 0) length++; @@ -312,58 +312,58 @@ { return (id)[[OFString_UTF8 alloc] initWithCharacters: string length: length]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string length: length]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string byteOrder: byteOrder]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string length: length]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string byteOrder: byteOrder]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string length: length @@ -530,58 +530,58 @@ { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } -+ (instancetype)stringWithUTF16String: (const uint16_t*)string ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string { return [[[self alloc] initWithUTF16String: string] autorelease]; } -+ (instancetype)stringWithUTF16String: (const uint16_t*)string ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string length: (size_t)length { return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } -+ (instancetype)stringWithUTF16String: (const uint16_t*)string ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF16String: string byteOrder: byteOrder] autorelease]; } -+ (instancetype)stringWithUTF16String: (const uint16_t*)string ++ (instancetype)stringWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF16String: string length: length byteOrder: byteOrder] autorelease]; } -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string { return [[[self alloc] initWithUTF32String: string] autorelease]; } -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length { return [[[self alloc] initWithUTF32String: string length: length] autorelease]; } -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string byteOrder: byteOrder] autorelease]; } -+ (instancetype)stringWithUTF32String: (const uint32_t*)string ++ (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string length: length @@ -716,34 +716,34 @@ [self release]; @throw e; } } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string { return [self initWithUTF16String: string length: of_string_utf16_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length { return [self initWithUTF16String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return [self initWithUTF16String: string length: of_string_utf16_length(string) byteOrder: byteOrder]; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { @try { [self doesNotRecognizeSelector: _cmd]; @@ -752,34 +752,34 @@ [self release]; @throw e; } } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string { return [self initWithUTF32String: string length: of_string_utf32_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length { return [self initWithUTF32String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return [self initWithUTF32String: string length: of_string_utf32_length(string) byteOrder: byteOrder]; } -- initWithUTF32String: (const uint32_t*)string +- initWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { @try { [self doesNotRecognizeSelector: _cmd]; @@ -2120,27 +2120,27 @@ inRange: of_range(0, length)]; return ret; } -- (const uint16_t*)UTF16String +- (const of_char16_t*)UTF16String { return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } -- (const uint16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder +- (const of_char16_t*)UTF16StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; - uint16_t *ret; + of_char16_t *ret; size_t i, j; BOOL swap = (byteOrder != OF_BYTE_ORDER_NATIVE); /* Allocate memory for the worst case */ - ret = [object allocMemoryWithSize: sizeof(uint16_t) + ret = [object allocMemoryWithSize: sizeof(of_char16_t) count: (length + 1) * 2]; j = 0; for (i = 0; i < length; i++) { @@ -2168,11 +2168,11 @@ } ret[j] = 0; @try { ret = [object resizeMemory: ret - size: sizeof(uint16_t) + size: sizeof(of_char16_t) count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } @@ -2193,22 +2193,22 @@ UTF16StringLength++; return UTF16StringLength; } -- (const of_unichar_t*)UTF32String +- (const of_char32_t*)UTF32String { return [self UTF32StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } -- (const of_unichar_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder +- (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; - of_unichar_t *ret; + of_char32_t *ret; - ret = [object allocMemoryWithSize: sizeof(of_unichar_t) + ret = [object allocMemoryWithSize: sizeof(of_char32_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -37,12 +37,12 @@ #import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" -extern const uint16_t of_iso_8859_15[256]; -extern const uint16_t of_windows_1252[256]; +extern const of_char16_t of_iso_8859_15[256]; +extern const of_char16_t of_windows_1252[256]; static inline int memcasecmp(const char *first, const char *second, size_t length) { size_t i; @@ -211,11 +211,11 @@ { self = [super init]; @try { size_t i, j; - const uint16_t *table; + const of_char16_t *table; if (encoding == OF_STRING_ENCODING_UTF_8 && cStringLength >= 3 && !memcmp(cString, "\xEF\xBB\xBF", 3)) { cString += 3; cStringLength -= 3; @@ -464,11 +464,11 @@ } return self; } -- initWithUTF16String: (const uint16_t*)string +- initWithUTF16String: (const of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @@ -502,11 +502,11 @@ if ((character & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; if ((character & 0xFC00) == 0xD800) { - uint16_t nextCharacter; + of_char16_t nextCharacter; if (length <= i + 1) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -576,11 +576,11 @@ } return self; } -- initWithUTF32String: (const of_unichar_t*)characters +- initWithUTF32String: (const of_char32_t*)characters length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @@ -1346,14 +1346,14 @@ } return ret; } -- (const of_unichar_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder +- (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; - of_unichar_t *ret; + of_char32_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) count: s->length + 1]; Index: src/iso_8859_15.m ================================================================== --- src/iso_8859_15.m +++ src/iso_8859_15.m @@ -12,13 +12,13 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#include +#import "OFString.h" -const uint16_t of_iso_8859_15[256] = { +const of_char16_t of_iso_8859_15[256] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, Index: src/windows_1252.m ================================================================== --- src/windows_1252.m +++ src/windows_1252.m @@ -12,13 +12,13 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#include +#import "OFString.h" -const uint16_t of_windows_1252[256] = { +const of_char16_t of_windows_1252[256] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,