ObjFW  Check-in [7dc3d12cad]

Overview
Comment:OFString: Improve exceptions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7dc3d12cadd98099e7210a2cad33c9f43add33ef42c6834b8d1fc717108fd995
User & Date: js on 2022-09-16 13:15:24
Other Links: manifest | tags
Context
2022-09-16
13:17
OFINIFile: Default to UTF-8 check-in: 2140e81b53 user: js tags: trunk
13:15
OFString: Improve exceptions check-in: 7dc3d12cad user: js tags: trunk
2022-09-12
14:34
Either restrict subclassing or reserve ivars check-in: c40a295629 user: js tags: trunk
Changes

Modified src/OFString.m from [c20b83a313] to [90a06f38bf].

1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
1364
1349
1350
1351
1352
1353
1354
1355

1356

1357
1358
1359
1360
1361
1362
1363







-
+
-







			@throw [OFInvalidEncodingException exception];

		cString[length] = '\0';

		return length;
#endif
	default:
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		@throw [OFInvalidArgumentException exception];
								 object: self];
	}
}

- (size_t)getCString: (char *)cString
	   maxLength: (size_t)maxLength
	    encoding: (OFStringEncoding)encoding
{
1431
1432
1433
1434
1435
1436
1437
1438

1439
1440
1441
1442
1443
1444
1445
1430
1431
1432
1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444







-
+







		} @catch (id e) {
			OFFreeMemory(cString);
			@throw e;
		}

		break;
	default:
		@throw [OFInvalidEncodingException exception];
		@throw [OFInvalidArgumentException exception];
	}

	@try {
		ret = [[OFData dataWithItemsNoCopy: cString
					     count: cStringLength + 1
				      freeWhenDone: true] items];
	} @catch (id e) {
1502
1503
1504
1505
1506
1507
1508
1509

1510
1511
1512
1513
1514
1515
1516
1501
1502
1503
1504
1505
1506
1507

1508
1509
1510
1511
1512
1513
1514
1515







-
+







	case OFStringEncodingCodepage850:
	case OFStringEncodingCodepage858:
	case OFStringEncodingMacRoman:
	case OFStringEncodingKOI8R:
	case OFStringEncodingKOI8U:
		return self.length;
	default:
		@throw [OFInvalidEncodingException exception];
		@throw [OFInvalidArgumentException exception];
	}
}

- (size_t)UTF8StringLength
{
	return [self cStringLengthWithEncoding: OFStringEncodingUTF8];
}

Modified src/OFUTF8String.m from [1455d494bf] to [c76e8c2ef7].

342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+







		CASE(OFStringEncodingKOI8R, OFKOI8RTable)
#endif
#ifdef HAVE_KOI8_U
		CASE(OFStringEncodingKOI8U, OFKOI8UTable)
#endif
#undef CASE
		default:
			@throw [OFInvalidEncodingException exception];
			@throw [OFInvalidArgumentException exception];
		}

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