Differences From Artifact [cb1b20524f]:
- File
src/OFString.m
— part of check-in
[9ddd33a258]
at
2013-01-12 17:29:24
on branch trunk
— Rename *UsingEncoding: to *WithEncoding:.
This reverts 5362941.
Even though *UsingEncoding: is what Foundation uses, *WithEncoding: is
more natural and is more consistent with the rest. Also, this means this
restores it to the API of 0.7. (user: js, size: 50018) [annotate] [blame] [check-ins using]
To Artifact [3b195e39ec]:
- File
src/OFString.m
— part of check-in
[545b6f740e]
at
2013-01-13 13:07:52
on branch trunk
— Add of_char{16,32}_t.
For ObjC++, these are defined to char{16,32}_t if C++11 is used. This
means passing e.g. a C++11 UTF-16 string to -[initWithUTF16String:]
works without a warning.For C11, this is not necessary, as char{16,32}_t are just typedef'd to
uint_least{16,32}_t in <uchar.h> and thus compatible to the definition
of of_char{16,32}_t. The reason for not defining of_char{16,32}_t to
char{16,32}_t when using C11 is that <uchar.h> might be missing and that
char{16,32}_t are not required to be UTF-{16,32}, whereas in C++, they
are required to be UTF-{16,32}. (user: js, size: 50107) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
139 140 141 142 143 144 145 | return 4; } return 0; } size_t | | | | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | return 4; } return 0; } size_t of_string_utf16_length(const of_char16_t *string) { size_t length = 0; while (*string++ != 0) length++; return length; } size_t of_string_utf32_length(const of_char32_t *string) { size_t length = 0; while (*string++ != 0) length++; return length; |
︙ | ︙ | |||
310 311 312 313 314 315 316 | - initWithCharacters: (const of_unichar_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithCharacters: string length: length]; } | | | | | | | | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | - initWithCharacters: (const of_unichar_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithCharacters: string length: length]; } - initWithUTF16String: (const of_char16_t*)string { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string]; } - initWithUTF16String: (const of_char16_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string length: length]; } - initWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string byteOrder: byteOrder]; } - 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 of_char32_t*)string { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string]; } - initWithUTF32String: (const of_char32_t*)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string length: length]; } - initWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string byteOrder: byteOrder]; } - 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 byteOrder: byteOrder]; } |
︙ | ︙ | |||
528 529 530 531 532 533 534 | + (instancetype)stringWithCharacters: (const of_unichar_t*)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } | | | | | | | | | | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | + (instancetype)stringWithCharacters: (const of_unichar_t*)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const of_char16_t*)string { return [[[self alloc] initWithUTF16String: string] autorelease]; } + (instancetype)stringWithUTF16String: (const of_char16_t*)string length: (size_t)length { return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const of_char16_t*)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF16String: string byteOrder: byteOrder] autorelease]; } + (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 of_char32_t*)string { return [[[self alloc] initWithUTF32String: string] autorelease]; } + (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length { return [[[self alloc] initWithUTF32String: string length: length] autorelease]; } + (instancetype)stringWithUTF32String: (const of_char32_t*)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string length: length byteOrder: byteOrder] autorelease]; } |
︙ | ︙ | |||
714 715 716 717 718 719 720 | abort(); } @catch (id e) { [self release]; @throw e; } } | | | | | | | | | | 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | abort(); } @catch (id e) { [self release]; @throw e; } } - initWithUTF16String: (const of_char16_t*)string { return [self initWithUTF16String: string length: of_string_utf16_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF16String: (const of_char16_t*)string length: (size_t)length { return [self initWithUTF16String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } - 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 of_char16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { [self release]; @throw e; } } - initWithUTF32String: (const of_char32_t*)string { return [self initWithUTF32String: string length: of_string_utf32_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF32String: (const of_char32_t*)string length: (size_t)length { return [self initWithUTF32String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } - 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 of_char32_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { @try { [self doesNotRecognizeSelector: _cmd]; abort(); } @catch (id e) { |
︙ | ︙ | |||
2118 2119 2120 2121 2122 2123 2124 | count: length]; [self getCharacters: ret inRange: of_range(0, length)]; return ret; } | | | | | | 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 | count: length]; [self getCharacters: ret inRange: of_range(0, length)]; return ret; } - (const of_char16_t*)UTF16String { return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } - (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]; 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(of_char16_t) count: (length + 1) * 2]; j = 0; for (i = 0; i < length; i++) { of_unichar_t c = characters[i]; |
︙ | ︙ | |||
2166 2167 2168 2169 2170 2171 2172 | ret[j++] = c; } } ret[j] = 0; @try { ret = [object resizeMemory: ret | | | 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 | ret[j++] = c; } } ret[j] = 0; @try { ret = [object resizeMemory: ret size: sizeof(of_char16_t) count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
2191 2192 2193 2194 2195 2196 2197 | for (i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } | | | | | | 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 | for (i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } - (const of_char32_t*)UTF32String { return [self UTF32StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } - (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; of_char32_t *ret; ret = [object allocMemoryWithSize: sizeof(of_char32_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) { size_t i; |
︙ | ︙ |