Differences From Artifact [e0471f5f58]:
- File
src/OFString.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 64664) [annotate] [blame] [check-ins using]
To Artifact [f26acdf614]:
- File src/OFString.m — part of check-in [37d2a81754] at 2017-05-07 21:25:56 on branch trunk — Use char{16,32}_t instead of of_char{16,32}_t (user: js, size: 64559) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
261 262 263 264 265 266 267 | return 4; } return 0; } size_t | | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | return 4; } return 0; } size_t of_string_utf16_length(const char16_t *string) { size_t length = 0; while (*string++ != 0) length++; return length; } size_t of_string_utf32_length(const char32_t *string) { size_t length = 0; while (*string++ != 0) length++; return length; |
︙ | ︙ | |||
448 449 450 451 452 453 454 | - initWithCharacters: (const of_unichar_t *)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithCharacters: string length: length]; } | | | | | | | | | | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | - initWithCharacters: (const of_unichar_t *)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithCharacters: string length: length]; } - initWithUTF16String: (const char16_t *)string { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string]; } - initWithUTF16String: (const char16_t *)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string length: length]; } - initWithUTF16String: (const char16_t *)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF16String: string byteOrder: byteOrder]; } - initWithUTF16String: (const 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 char32_t *)string { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string]; } - initWithUTF32String: (const char32_t *)string length: (size_t)length { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string length: length]; } - initWithUTF32String: (const char32_t *)string byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string byteOrder: byteOrder]; } - initWithUTF32String: (const char32_t *)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return (id)[[OFString_UTF8 alloc] initWithUTF32String: string length: length byteOrder: byteOrder]; } |
︙ | ︙ | |||
654 655 656 657 658 659 660 | + (instancetype)stringWithCharacters: (const of_unichar_t *)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } | | | | | | | | | | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | + (instancetype)stringWithCharacters: (const of_unichar_t *)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const char16_t *)string { return [[[self alloc] initWithUTF16String: string] autorelease]; } + (instancetype)stringWithUTF16String: (const char16_t *)string length: (size_t)length { return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const char16_t *)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF16String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF16String: (const 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 char32_t *)string { return [[[self alloc] initWithUTF32String: string] autorelease]; } + (instancetype)stringWithUTF32String: (const char32_t *)string length: (size_t)length { return [[[self alloc] initWithUTF32String: string length: length] autorelease]; } + (instancetype)stringWithUTF32String: (const char32_t *)string byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const char32_t *)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { return [[[self alloc] initWithUTF32String: string length: length byteOrder: byteOrder] autorelease]; } |
︙ | ︙ | |||
831 832 833 834 835 836 837 | - initWithCharacters: (const of_unichar_t *)string length: (size_t)length { OF_INVALID_INIT_METHOD } | | | | | | | | | | 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | - initWithCharacters: (const of_unichar_t *)string length: (size_t)length { OF_INVALID_INIT_METHOD } - initWithUTF16String: (const char16_t *)string { return [self initWithUTF16String: string length: of_string_utf16_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF16String: (const char16_t *)string length: (size_t)length { return [self initWithUTF16String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF16String: (const char16_t *)string byteOrder: (of_byte_order_t)byteOrder { return [self initWithUTF16String: string length: of_string_utf16_length(string) byteOrder: byteOrder]; } - initWithUTF16String: (const char16_t *)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { OF_INVALID_INIT_METHOD } - initWithUTF32String: (const char32_t *)string { return [self initWithUTF32String: string length: of_string_utf32_length(string) byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF32String: (const char32_t *)string length: (size_t)length { return [self initWithUTF32String: string length: length byteOrder: OF_BYTE_ORDER_NATIVE]; } - initWithUTF32String: (const char32_t *)string byteOrder: (of_byte_order_t)byteOrder { return [self initWithUTF32String: string length: of_string_utf32_length(string) byteOrder: byteOrder]; } - initWithUTF32String: (const char32_t *)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { OF_INVALID_INIT_METHOD } - initWithFormat: (OFConstantString *)format, ... |
︙ | ︙ | |||
2609 2610 2611 2612 2613 2614 2615 | count: length]; [self getCharacters: ret inRange: of_range(0, length)]; return ret; } | | | | | | 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 | count: length]; [self getCharacters: ret inRange: of_range(0, length)]; return ret; } - (const char16_t *)UTF16String { return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } - (const 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]; char16_t *ret; size_t j; bool swap = (byteOrder != OF_BYTE_ORDER_NATIVE); /* Allocate memory for the worst case */ ret = [object allocMemoryWithSize: sizeof(char16_t) count: (length + 1) * 2]; j = 0; for (size_t i = 0; i < length; i++) { of_unichar_t c = characters[i]; if (c > 0x10FFFF) |
︙ | ︙ | |||
2655 2656 2657 2658 2659 2660 2661 | ret[j++] = c; } } ret[j] = 0; @try { ret = [object resizeMemory: ret | | | 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 | ret[j++] = c; } } ret[j] = 0; @try { ret = [object resizeMemory: ret size: sizeof(char16_t) count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
2680 2681 2682 2683 2684 2685 2686 | for (size_t i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } | | | | | | 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 | for (size_t i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } - (const char32_t *)UTF32String { return [self UTF32StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } - (const char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; char32_t *ret; ret = [object allocMemoryWithSize: sizeof(char32_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) |
︙ | ︙ |