Comment: | Allow strings to contain \0
In order to not accidentally have C strings with \0, an In order to get a C string with \0 anyway, a new method |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6fbc3b18c717dc97bc0169d28f19c0fc |
User & Date: | js on 2024-10-27 22:27:20 |
Other Links: | manifest | tags |
2024-10-27
| ||
22:37 | • Fixed ticket [134d90a996]: String \0 safety plus 4 other changes artifact: 376510cc34 user: js | |
2024-10-27
| ||
23:38 | OFSystemInfo: Fix \0 in +[CPUModel] on macOS check-in: e061c2b66e user: js tags: trunk | |
22:27 | Allow strings to contain \0 check-in: 6fbc3b18c7 user: js tags: trunk | |
18:38 | Remove nullable in .m files check-in: 7d1275cb49 user: js tags: trunk | |
Modified src/OFConstantString.m from [e8a18a09ea] to [03e8d1030f].
︙ | |||
95 96 97 98 99 100 101 | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | - + | return; ivars = OFAllocZeroedMemory(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (_OFUTF8StringCheck(ivars->cString, ivars->cStringLength, |
︙ |
Modified src/OFMutableUTF8String.m from [521dc8393f] to [027a5197e3].
︙ | |||
204 205 206 207 208 209 210 211 212 213 214 215 216 217 | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | + + + | if (_s->isUTF8) idx = _OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); if (idx >= _s->cStringLength) @throw [OFOutOfRangeException exception]; if (character == 0) _s->containsNull = true; /* Shortcut if old and new character both are ASCII */ if (character < 0x80 && !(_s->cString[idx] & 0x80)) { _s->hasHash = false; _s->cString[idx] = character; return; } |
︙ | |||
268 269 270 271 272 273 274 | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | - + + | if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } |
︙ | |||
297 298 299 300 301 302 303 | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | - + + | if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } |
︙ | |||
350 351 352 353 354 355 356 | 355 356 357 358 359 360 361 362 363 364 365 366 367 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | - + + + + - + - + + + + + + + | { const char *UTF8String; size_t UTF8StringLength; if (string == nil) @throw [OFInvalidArgumentException exception]; |
︙ | |||
448 449 450 451 452 453 454 | 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 | - + + + + - + | if (idx > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) idx = _OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); |
︙ | |||
500 501 502 503 504 505 506 507 508 509 510 511 512 513 | 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | + + + + + + + + | memmove(_s->cString + start, _s->cString + end, _s->cStringLength - end); _s->hasHash = false; _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; if (_s->containsNull) { _s->containsNull = false; for (size_t i = 0; i < _s->cStringLength; i++) if (_s->cString[i] == '\0') _s->containsNull = true; } @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } |
︙ | |||
533 534 535 536 537 538 539 | 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | - + + | if (_s->isUTF8) { start = _OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = _OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } |
︙ | |||
572 573 574 575 576 577 578 579 580 | 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | + + + - + + + + + + + + + - - + + + + | _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; if (((OFMutableUTF8String *)replacement)->_s->containsNull) _s->containsNull = true; } else { switch (_OFUTF8StringCheck(replacementString, replacementLength, |
︙ | |||
665 666 667 668 669 670 671 672 673 | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | + + + - + + + + + + + + + | _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; if (((OFMutableUTF8String *)replacement)->_s->containsNull) _s->containsNull = true; } else { switch (_OFUTF8StringCheck(replacementString, replacementLength, |
︙ |
Modified src/OFSequencedPacketSocket.h from [68ab17bfbd] to [fa3cdbb7dd].
︙ | |||
273 274 275 276 277 278 279 | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | - + - + | runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * |
︙ |
Modified src/OFString+JSONParsing.m from [87273342cc] to [08913e2453].
︙ | |||
186 187 188 189 190 191 192 193 194 195 196 197 198 199 | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | + + + + | buffer[i++] = '\r'; (*pointer)++; break; case 't': buffer[i++] = '\t'; (*pointer)++; break; case '0': buffer[i++] = '\0'; (*pointer)++; break; /* Parse Unicode escape sequence */ case 'u':; OFChar16 c1, c2; OFUnichar c; size_t l; c1 = parseUnicodeEscape(*pointer - 1, stop); |
︙ |
Modified src/OFString.h from [5672da673b] to [dfff2d8730].
︙ | |||
919 920 921 922 923 924 925 926 927 928 929 930 931 932 | 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 | + + + + + + + + + + + + + | * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ - (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding; /** * @brief Returns the OFString as an insecure C string (meaning it can contain * `\0`) in the specified encoding. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ - (const char *)insecureCStringWithEncoding: (OFStringEncoding)encoding; /** * @brief Returns the number of bytes the string needs in the specified * encoding. * * @param encoding The encoding for the string * @return The number of bytes the string needs in the specified encoding. * @throw OFInvalidEncodingException The string cannot be represented in the |
︙ |
Modified src/OFString.m from [0a6f9138dd] to [235c6ba0c3].
︙ | |||
99 100 101 102 103 104 105 | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | - + + - + + - + - + - + - + - + - + - + - + - + - + - + - + - + | # endif #endif @interface OFString () - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding |
︙ | |||
373 374 375 376 377 378 379 | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | - + + - + + + + + - + | memcpy(copy, string, length + 1); return copy; } #ifdef OF_OBJFW_RUNTIME static bool |
︙ | |||
407 408 409 410 411 412 413 | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | - + | void *storage; if (length == 0) return (id)@""; #ifdef OF_OBJFW_RUNTIME if (length <= MAX_TAGGED_POINTER_LENGTH && |
︙ | |||
435 436 437 438 439 440 441 | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | - + | void *storage; if (UTF8StringLength == 0) return (id)@""; #ifdef OF_OBJFW_RUNTIME if (UTF8StringLength <= MAX_TAGGED_POINTER_LENGTH && |
︙ | |||
485 486 487 488 489 490 491 | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | - + | void *storage; if (length == 0) return (id)@""; #ifdef OF_OBJFW_RUNTIME if (length <= MAX_TAGGED_POINTER_LENGTH && |
︙ | |||
521 522 523 524 525 526 527 | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | - + | void *storage; if (cStringLength == 0) return (id)@""; #ifdef OF_OBJFW_RUNTIME if (cStringLength <= MAX_TAGGED_POINTER_LENGTH && |
︙ | |||
565 566 567 568 569 570 571 | 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | - + - - + + - + | { if (length == 0) return (id)@""; #ifdef OF_OBJFW_RUNTIME if (length <= MAX_TAGGED_POINTER_LENGTH) { char buffer[MAX_TAGGED_POINTER_LENGTH]; |
︙ | |||
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 | 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 | + + + + + + - + | return self; } - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding lossy: (bool)lossy insecure: (bool)insecure { const OFUnichar *characters = self.characters; size_t i, length = self.length; switch (encoding) { case OFStringEncodingUTF8:; size_t j = 0; for (i = 0; i < length; i++) { char buffer[4]; size_t len; if OF_UNLIKELY (!insecure && characters[i] == 0) @throw [OFInvalidEncodingException exception]; |
︙ | |||
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 | 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 | + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + - + + + - + + | return j; case OFStringEncodingASCII: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (!insecure && characters[i] == 0) @throw [OFInvalidEncodingException exception]; if OF_UNLIKELY (characters[i] > 0x80) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; case OFStringEncodingISO8859_1: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (!insecure && characters[i] == 0) @throw [OFInvalidEncodingException exception]; if OF_UNLIKELY (characters[i] > 0xFF) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; #ifdef HAVE_ISO_8859_2 case OFStringEncodingISO8859_2: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!_OFUnicodeToISO8859_2(characters, (unsigned char *)cString, |
︙ | |||
1496 1497 1498 1499 1500 1501 1502 | 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 | - + + | case OFStringEncodingKOI8U: cString = OFAllocMemory(length + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: length + 1 encoding: encoding |
︙ | |||
1521 1522 1523 1524 1525 1526 1527 | 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 | - + + + - + + + + + + + + + + - + + + - + + + + + | } return ret; } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { |
︙ | |||
1797 1798 1799 1800 1801 1802 1803 1804 1805 | 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 | + - + + | [JSON replaceOccurrencesOfString: @"\b" withString: @"\\b"]; [JSON replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [JSON replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [JSON replaceOccurrencesOfString: @"\t" withString: @"\\t"]; if (options & OFJSONRepresentationOptionJSON5) { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"]; [JSON replaceOccurrencesOfString: @"\0" withString: @"\\0"]; if (options & OFJSONRepresentationOptionIsIdentifier) { |
︙ | |||
1859 1860 1861 1862 1863 1864 1865 | 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 | + - + | data = [OFMutableData dataWithCapacity: length + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: [self insecureCStringWithEncoding: OFStringEncodingUTF8] |
︙ | |||
2654 2655 2656 2657 2658 2659 2660 | 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 | - + | /* Allocate memory for the worst case */ buffer = OFAllocMemory((length + 1) * 2, sizeof(OFChar16)); j = 0; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; |
︙ | |||
2729 2730 2731 2732 2733 2734 2735 | 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 | + + + + - + - + | const OFChar32 *ret; buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { [self getCharacters: buffer inRange: OFMakeRange(0, length)]; buffer[length] = 0; for (size_t i = 0; i < length; i++) { if (buffer[i] == 0) @throw [OFInvalidEncodingException exception]; |
︙ |
Modified src/OFTCPSocket.h from [3d8f48f978] to [c7a38bf638].
︙ | |||
27 28 29 30 31 32 33 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | - + | @class OFTCPSocket; @class OFString; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * |
︙ |
Modified src/OFUTF8String+Private.h from [ccfb13bd6d] to [84456dce78].
︙ | |||
27 28 29 30 31 32 33 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | - + | length: (size_t)UTF8StringLength storage: (char *)storage OF_METHOD_FAMILY(init); @end #ifdef __cplusplus extern "C" { #endif |
︙ |
Modified src/OFUTF8String.h from [fe9a65353f] to [06f893bbd3].
︙ | |||
29 30 31 32 33 34 35 | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | - + | * Since constant strings don't have `_storage`, they have to allocate * it on the first access. Strings created at runtime just set the * pointer to `&_storage`. */ struct OFUTF8StringIvars { char *cString; size_t cStringLength; |
︙ |
Modified src/OFUTF8String.m from [eb22322b98] to [731d0242b9].
︙ | |||
88 89 90 91 92 93 94 | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | - + + + + + + | return OFOrderedAscending; } return OFOrderedSame; } int |
︙ | |||
151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | + + + | i += 3; tmpLength -= 3; } if (length != NULL) *length = tmpLength; if (containsNull != NULL) *containsNull = tmpContainsNull; return isUTF8; } static size_t positionToIndex(const char *string, size_t position) { size_t idx = position; |
︙ | |||
214 215 216 217 218 219 220 | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | - + | _s = &_storage; _s->cString = storage; _s->cStringLength = UTF8StringLength; switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, |
︙ | |||
258 259 260 261 262 263 264 | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | - + | _s->cString = OFAllocMemory(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OFStringEncodingUTF8 || encoding == OFStringEncodingASCII) { switch (_OFUTF8StringCheck(cString, cStringLength, |
︙ | |||
291 292 293 294 295 296 297 298 299 | 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | + + + + - | if (!(cString[i] & 0x80)) { _s->cString[j++] = cString[i]; continue; } _s->isUTF8 = true; if OF_UNLIKELY (cString[i] == '\0') _s->containsNull = true; bytes = _OFUTF8StringEncode( (uint8_t)cString[i], buffer); |
︙ | |||
382 383 384 385 386 387 388 389 390 391 392 393 394 395 | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | + + + | if (unichar < 0x7F) { _s->cString[j++] = (char)unichar; continue; } _s->isUTF8 = true; if OF_UNLIKELY (cString[i] == '\0') _s->containsNull = true; byteLength = _OFUTF8StringEncode(unichar, buffer); if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; _s->cString = OFResizeMemory(_s->cString, |
︙ | |||
429 430 431 432 433 434 435 | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | - + | if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (_OFUTF8StringCheck(UTF8String, UTF8StringLength, |
︙ | |||
459 460 461 462 463 464 465 | 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 | - + + + - + + + - + - + | @try { _s = &_storage; _s->cStringLength = string.UTF8StringLength; _s->length = string.length; _s->cString = OFAllocMemory(_s->cStringLength + 1, 1); |
︙ | |||
507 508 509 510 511 512 513 514 515 516 517 518 519 520 | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | + + + | _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; if OF_UNLIKELY (characters[i] == 0) _s->containsNull = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; |
︙ | |||
593 594 595 596 597 598 599 600 601 602 603 604 605 606 | 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | + + + | if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; if OF_UNLIKELY (character == 0) _s->containsNull = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { |
︙ | |||
641 642 643 644 645 646 647 | 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 | - - - + + + - + + + | _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { char buffer[4]; |
︙ | |||
702 703 704 705 706 707 708 | 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | - + | arguments)) == -1) @throw [OFInvalidFormatException exception]; _s->cStringLength = cStringLength; @try { switch (_OFUTF8StringCheck(tmp, cStringLength, |
︙ | |||
736 737 738 739 740 741 742 743 744 745 746 747 748 749 | 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | + + + | [super dealloc]; } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { if (_s->containsNull) @throw [OFInvalidEncodingException exception]; switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: if (_s->cStringLength + 1 > maxLength) |
︙ | |||
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | + + + + + + + + + + + + + + + + + + + + | maxLength: maxLength encoding: encoding]; } } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { if (_s->containsNull) @throw [OFInvalidEncodingException exception]; switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: return _s->cString; default: return [super cStringWithEncoding: encoding]; } } - (const char *)insecureCStringWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: return _s->cString; default: return [super insecureCStringWithEncoding: encoding]; } } - (const char *)UTF8String { if (_s->containsNull) @throw [OFInvalidEncodingException exception]; return _s->cString; } - (size_t)length { return _s->length; } |
︙ | |||
816 817 818 819 820 821 822 | 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 899 900 901 902 903 | - + + + - + + | return false; if (([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) && _s->hasHash && string->_s->hasHash && _s->hash != string->_s->hash) return false; |
︙ | |||
864 865 866 867 868 869 870 | 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | - + + | size_t i, j; #endif int compare; if (string == self) return OFOrderedSame; |
︙ | |||
1008 1009 1010 1011 1012 1013 1014 | 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | - + + | objc_autoreleasePoolPop(pool); } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { |
︙ | |||
1066 1067 1068 1069 1070 1071 1072 | 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | - + + | } return OFMakeRange(OFNotFound, 0); } - (bool)containsString: (OFString *)string { |
︙ | |||
1108 1109 1110 1111 1112 1113 1114 | 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 | - + + + + - + | - (bool)hasPrefix: (OFString *)prefix { size_t cStringLength = prefix.UTF8StringLength; if (cStringLength > _s->cStringLength) return false; |
︙ | |||
1141 1142 1143 1144 1145 1146 1147 | 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | - + | @throw [OFInvalidArgumentException exception]; if (delimiter.length == 0) return [OFArray arrayWithObject: self]; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); |
︙ | |||
1212 1213 1214 1215 1216 1217 1218 | 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 | - + + + + + + | } return ret; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { |
︙ |
Modified src/encodings/codepage-437.m from [0e1d4e03c0] to [ae0ed7f16e].
︙ | |||
130 131 132 133 134 135 136 | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage437(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/codepage-850.m from [116375a4bc] to [fa7a3fd8d6].
︙ | |||
105 106 107 108 109 110 111 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage850(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/codepage-852.m from [2e105e7181] to [555c3df35d].
︙ | |||
110 111 112 113 114 115 116 | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage852(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/codepage-858.m from [0a443ea671] to [2c6eb1a5f6].
︙ | |||
111 112 113 114 115 116 117 | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToCodepage858(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/iso-8859-15.m from [25e41edd49] to [24cf09fca0].
︙ | |||
61 62 63 64 65 66 67 | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | - + - + + + + + + | static const unsigned char page20[] = { 0xA4 }; static const uint8_t page20Start = 0xAC; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_15(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/iso-8859-2.m from [bd3f7dada7] to [a88030091f].
︙ | |||
81 82 83 84 85 86 87 | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0xFF, 0x00, 0xB2, 0x00, 0xBD }; static const uint8_t page2Start = 0xC7; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_2(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/iso-8859-3.m from [bc9ab876ae] to [bf5185ce65].
︙ | |||
78 79 80 81 82 83 84 | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | - + - + + + + + + | static const unsigned char page2[] = { 0xA2, 0xFF }; static const uint8_t page2Start = 0xD8; bool OF_VISIBILITY_HIDDEN _OFUnicodeToISO8859_3(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/koi8-r.m from [7d684b26ac] to [47c8151c6a].
︙ | |||
116 117 118 119 120 121 122 | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToKOI8R(const OFUnichar *input, unsigned char *output, size_t length, |
︙ |
Modified src/encodings/koi8-u.m from [0f9ae48dcf] to [ae62fae518].
︙ | |||
124 125 126 127 128 129 130 | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | - + - + + + + + + | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OF_VISIBILITY_HIDDEN _OFUnicodeToKOI8U(const OFUnichar *input, unsigned char *output, size_t length, |
︙ |
Modified src/encodings/mac-roman.m from [48622afc6e] to [6cd071203c].
︙ | |||
150 151 152 153 154 155 156 | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | - + - + + + + + + | static const unsigned char pageFB[] = { 0xDE, 0xDF }; static const uint8_t pageFBStart = 0x01; bool OF_VISIBILITY_HIDDEN _OFUnicodeToMacRoman(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/windows-1250.m from [66d83a46d2] to [bfff0cf391].
︙ | |||
114 115 116 117 118 119 120 | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | - + - + + + + + + | static const unsigned char page21[] = { 0x99 }; static const uint8_t page21Start = 0x22; bool OF_VISIBILITY_HIDDEN _OFUnicodeToWindows1250(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/windows-1251.m from [fb08e37f56] to [4405821c2a].
︙ | |||
103 104 105 106 107 108 109 | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | - + - + + + + + + | 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99 }; static const uint8_t page21Start = 0x16; bool OF_VISIBILITY_HIDDEN _OFUnicodeToWindows1251(const OFUnichar *input, unsigned char *output, |
︙ |
Modified src/encodings/windows-1252.m from [1577a4fe9c] to [0d87252cdf].
︙ | |||
99 100 101 102 103 104 105 | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | - + - + + + + + + | static const unsigned char page21[] = { 0x99 }; static const uint8_t page21Start = 0x22; bool OF_VISIBILITY_HIDDEN _OFUnicodeToWindows1252(const OFUnichar *input, unsigned char *output, |
︙ |
Modified tests/OFJSONTests.m from [2ee8657285] to [4578e0b89d].
︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | - + - + | @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end |
︙ | |||
59 60 61 62 63 64 65 | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - + - + - + | { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, |
︙ |