ObjFW  Diff

Differences From Artifact [bb5fb35102]:

To Artifact [e613d6ae06]:


36
37
38
39
40
41
42
43

44
45
46
47

48
49
50

51
52
53

54
55
56
57
58
59
60
61
36
37
38
39
40
41
42

43
44
45
46

47
48
49

50
51
52

53

54
55
56
57
58
59
60







-
+



-
+


-
+


-
+
-








static OFString *module = @"OFString";
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,
	0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC
	0
};

@interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate>
@end

@implementation EntityHandler
-	   (OFString*)string: (OFString*)string
153
154
155
156
157
158
159
160
161




162
163



164
165
166
167




168
169



170
171
172
173
174
175
176
152
153
154
155
156
157
158


159
160
161
162
163

164
165
166
167
168


169
170
171
172
173

174
175
176
177
178
179
180
181
182
183







-
-
+
+
+
+

-
+
+
+


-
-
+
+
+
+

-
+
+
+








	TEST(@"+[stringWithUTF8String:length:]",
	    (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]) &&
	    [is isEqual: @"testäöü"])

399
400
401
402
403
404
405
406
407


408
409
410
411
412
413
414
406
407
408
409
410
411
412


413
414
415
416
417
418
419
420
421







-
-
+
+








	EXPECT_EXCEPTION(@"Detect out of range in -[hexadecimalValue]",
	    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
	    !memcmp(u16a, sutf16str + 1, sizeof(sutf16str) - sizeof(uint16_t)))
#endif