ObjFW  Check-in [d6a8d57148]

Overview
Comment:OFString: Fix converting from some encodings
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d6a8d5714863b77cf5f2c4ec85548cfe8ed4e5500db8c00055c0619d12c4ccde
User & Date: js on 2024-08-24 22:19:53
Other Links: manifest | tags
Context
2024-08-24
23:41
Don't assume all custom string classes use Unicode check-in: 82c5846734 user: js tags: trunk
22:20
OFString: Fix converting from some encodings check-in: 6e79f005c4 user: js tags: 1.1
22:19
OFString: Fix converting from some encodings check-in: d6a8d57148 user: js tags: trunk
20:02
Minor style fix check-in: 0ab4647723 user: js tags: trunk
Changes

Modified src/OFUTF8String.m from [494018f979] to [69877c8b33].

368
369
370
371
372
373
374
375

376
377
378
379
380



381
382
383
384





385
386
387

388
389
390
391
392
393
394
368
369
370
371
372
373
374

375





376
377
378
379
380
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396
397







-
+
-
-
-
-
-
+
+
+




+
+
+
+
+

-

+







		j = 0;
		for (size_t i = 0; i < cStringLength; i++) {
			unsigned char character = (unsigned char)cString[i];
			OFUnichar unichar;
			char buffer[4];
			size_t byteLength;

			if (character < tableOffset) {
			if (character >= tableOffset)
				_s->cString[j++] = cString[i];
				continue;
			}

			unichar = table[character - tableOffset];
				unichar = table[character - tableOffset];
			else
				unichar = character;

			if (unichar == 0xFFFF)
				@throw [OFInvalidEncodingException exception];

			if (unichar < 0x7F) {
				_s->cString[j++] = (char)unichar;
				continue;
			}

			_s->isUTF8 = true;
			byteLength = _OFUTF8StringEncode(unichar, buffer);

			byteLength = _OFUTF8StringEncode(unichar, buffer);
			if (byteLength == 0)
				@throw [OFInvalidEncodingException exception];

			_s->cStringLength += byteLength - 1;
			_s->cString = OFResizeMemory(_s->cString,
			    _s->cStringLength + 1, 1);

Modified tests/OFStringTests.m from [12b44c5424] to [e338ffd3a7].

261
262
263
264
265
266
267
268
269



270
271
272
273
274
275
276
261
262
263
264
265
266
267


268
269
270
271
272
273
274
275
276
277







-
-
+
+
+







		     encoding: OFStringEncodingISO8859_1], @"äöü");
}

#ifdef HAVE_ISO_8859_15
- (void)testStringWithCStringEncodingISO8859_15
{
	OTAssertEqualObjects([self.stringClass
	    stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
		     encoding: OFStringEncodingISO8859_15], @"€ŠšŽžŒœŸ");
	    stringWithCString: "a\x80\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
		     encoding: OFStringEncodingISO8859_15],
	    @"a\xC2\x80€ŠšŽžŒœŸ");
}
#endif

#ifdef HAVE_WINDOWS_1250
- (void)testStringWithCStringEncodingWindows1250
{
	OTAssertEqualObjects([self.stringClass