ObjFW  Check-in [beae8473fb]

Overview
Comment:-[OFString decomposedStringWithCanonicalMapping]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: beae8473fb5792705f0b9c645c3f7080064256b25986e5e82517ce24e6a8bd53
User & Date: js on 2017-07-02 11:55:22
Other Links: manifest | tags
Context
2017-07-02
13:16
TableGenerator: Generate decomp compat tables check-in: 4edfb80db7 user: js tags: trunk
11:55
-[OFString decomposedStringWithCanonicalMapping] check-in: beae8473fb user: js tags: trunk
2017-07-01
19:49
Update Xcode project to Xcode 9 check-in: 21b69ce7a7 user: js tags: trunk
Changes

Modified src/OFConstantString.m from [76865d67da] to [3d83fd1fce].

602
603
604
605
606
607
608









609
610
611
612
613
614
615

- (const char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
	[self finishInitialization];

	return [self UTF32StringWithByteOrder: byteOrder];
}










- (void)writeToFile: (OFString *)path
{
	[self finishInitialization];

	[self writeToFile: path];
}







>
>
>
>
>
>
>
>
>







602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

- (const char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
	[self finishInitialization];

	return [self UTF32StringWithByteOrder: byteOrder];
}

#ifdef OF_HAVE_UNICODE_TABLES
- (OFString *)decomposedStringWithCanonicalMapping
{
	[self finishInitialization];

	return [self decomposedStringWithCanonicalMapping];
}
#endif

- (void)writeToFile: (OFString *)path
{
	[self finishInitialization];

	[self writeToFile: path];
}

Modified src/OFString.h from [5f1355b3eb] to [a96c6fa4a6].

1097
1098
1099
1100
1101
1102
1103









1104
1105
1106
1107
1108
1109
1110
 * 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 char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
    OF_RETURNS_INNER_POINTER;










#ifdef OF_HAVE_FILES
/*!
 * @brief Writes the string into the specified file using UTF-8 encoding.
 *
 * @param path The path of the file to write to
 */







>
>
>
>
>
>
>
>
>







1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
 * 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 char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
    OF_RETURNS_INNER_POINTER;

#ifdef OF_HAVE_UNICODE_TABLES
/*!
 * @brief Returns the string in Unicode Normalization Form D (NFD).
 *
 * @return The string in Unicode Normalization Form D (NFD)
 */
- (OFString *)decomposedStringWithCanonicalMapping;
#endif

#ifdef OF_HAVE_FILES
/*!
 * @brief Writes the string into the specified file using UTF-8 encoding.
 *
 * @param path The path of the file to write to
 */

Modified src/OFString.m from [b7816611b8] to [6d858b8401].

2707
2708
2709
2710
2711
2712
2713
































2714
2715
2716
2717
2718
2719
2720

	if (byteOrder != OF_BYTE_ORDER_NATIVE)
		for (size_t i = 0; i < length; i++)
			ret[i] = OF_BSWAP32(ret[i]);

	return ret;
}

































#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
	[self writeToFile: path
		 encoding: OF_STRING_ENCODING_UTF_8];
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752

	if (byteOrder != OF_BYTE_ORDER_NATIVE)
		for (size_t i = 0; i < length; i++)
			ret[i] = OF_BSWAP32(ret[i]);

	return ret;
}

#ifdef OF_HAVE_UNICODE_TABLES
- (OFString *)decomposedStringWithCanonicalMapping
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = [self characters];
	size_t length = [self length];

	for (size_t i = 0; i < length; i++) {
		of_unichar_t c = characters[i];
		const char *const *table;

		if (c >= OF_UNICODE_DECOMPOSITION_TABLE_SIZE) {
			[ret appendCharacters: &c
				       length: 1];
			continue;
		}

		table = of_unicode_decomposition_table[c >> 8];
		if (table != NULL && table[c & 0xFF] != NULL)
			[ret appendUTF8String: table[c & 0xFF]];
		else
			[ret appendCharacters: &c
				       length: 1];
	}

	objc_autoreleasePoolPop(pool);

	return ret;
}
#endif

#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
	[self writeToFile: path
		 encoding: OF_STRING_ENCODING_UTF_8];
}

Modified tests/OFStringTests.m from [f7406dd54d] to [d944d8d727].

896
897
898
899
900
901
902




903
904
905
906
907
908
909
	    R([s[0] deleteTrailingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[deleteEnclosingWhitespaces]",
	    (s[0] = [mutableStringClass stringWithString: whitespace[0]]) &&
	    R([s[0] deleteEnclosingWhitespaces]) && [s[0] isEqual: @"asd"] &&
	    (s[0] = [mutableStringClass stringWithString: whitespace[1]]) &&
	    R([s[0] deleteEnclosingWhitespaces]) && [s[0] isEqual: @""])





	TEST(@"-[stringByXMLEscaping]",
	    (is = [C(@"<hello> &world'\"!&") stringByXMLEscaping]) &&
	    [is isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])

	TEST(@"-[stringByXMLUnescaping]",
	    [[is stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&







>
>
>
>







896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
	    R([s[0] deleteTrailingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[deleteEnclosingWhitespaces]",
	    (s[0] = [mutableStringClass stringWithString: whitespace[0]]) &&
	    R([s[0] deleteEnclosingWhitespaces]) && [s[0] isEqual: @"asd"] &&
	    (s[0] = [mutableStringClass stringWithString: whitespace[1]]) &&
	    R([s[0] deleteEnclosingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[decomposedStringWithCanonicalMapping]",
	    [[@"H\xC3\xA4ll\xC3\xB6" decomposedStringWithCanonicalMapping]
	    isEqual: @"H\x61\xCC\x88ll\x6F\xCC\x88"]);

	TEST(@"-[stringByXMLEscaping]",
	    (is = [C(@"<hello> &world'\"!&") stringByXMLEscaping]) &&
	    [is isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])

	TEST(@"-[stringByXMLUnescaping]",
	    [[is stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&