Differences From Artifact [50da202bb8]:
- File
src/OFMutableString_UTF8.m
— part of check-in
[c5ef582958]
at
2013-03-04 17:20:15
on branch trunk
— Replace BOOL with bool.
The only places where BOOL is left are those where they are required by
the ABI. (user: js, size: 20207) [annotate] [blame] [check-ins using]
To Artifact [7fb8de4d28]:
- File
src/OFMutableString_UTF8.m
— part of check-in
[3d16a30f41]
at
2013-06-22 12:12:36
on branch trunk
— Rework exceptions.
This mostly removes the argument for the class in which the exception
occurred. As backtraces were recently added for all platforms, the
passed class does not give any extra information on where the exception
occurred anymore.This also removes a few other arguments which were not too helpful. In
the past, the idea was to pass as many arguments as possible so that it
is easier to find the origin of the exception. However, as backtraces
are a much better way to find the origin, those are not useful anymore
and just make the exception more cumbersome to use. The rule is now to
only pass arguments that might help in recovering from the exception or
provide information that is otherwise not easily accessible. (user: js, size: 19565) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
123 124 125 126 127 128 129 | } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) { [self freeMemory: unicodeString]; | | < | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) { [self freeMemory: unicodeString]; @throw [OFInvalidEncodingException exception]; } switch (c) { case ' ': case '\t': case '\n': case '\r': |
︙ | ︙ | |||
157 158 159 160 161 162 163 | newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { [self freeMemory: unicodeString]; | | < | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { [self freeMemory: unicodeString]; @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = [self allocMemoryWithSize: newCStringLength + 1]; |
︙ | ︙ | |||
180 181 182 183 184 185 186 | for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { [self freeMemory: unicodeString]; [self freeMemory: newCString]; | | < | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { [self freeMemory: unicodeString]; [self freeMemory: newCString]; @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; [self freeMemory: unicodeString]; |
︙ | ︙ | |||
213 214 215 216 217 218 219 | size_t lenNew, lenOld; if (_s->isUTF8) index = of_string_utf8_get_position(_s->cString, index, _s->cStringLength); if (index > _s->cStringLength) | | | < | < | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | size_t lenNew, lenOld; if (_s->isUTF8) index = of_string_utf8_get_position(_s->cString, index, _s->cStringLength); if (index > _s->cStringLength) @throw [OFOutOfRangeException exception]; /* Shortcut if old and new character both are ASCII */ if (!(character & 0x80) && !(_s->cString[index] & 0x80)) { _s->hashed = false; _s->cString[index] = character; return; } if ((lenNew = of_string_utf8_encode(character, buffer)) == 0) @throw [OFInvalidEncodingException exception]; if ((lenOld = of_string_utf8_decode(_s->cString + index, _s->cStringLength - index, &c)) == 0) @throw [OFInvalidEncodingException exception]; _s->hashed = false; if (lenNew == lenOld) memcpy(_s->cString + index, buffer, lenNew); else if (lenNew > lenOld) { _s->cString = [self resizeMemory: _s->cString |
︙ | ︙ | |||
287 288 289 290 291 292 293 | } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: | | < | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + UTF8StringLength + 1]; memcpy(_s->cString + _s->cStringLength, UTF8String, |
︙ | ︙ | |||
317 318 319 320 321 322 323 | } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: | | < | 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + UTF8StringLength + 1]; memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); |
︙ | ︙ | |||
363 364 365 366 367 368 369 | } - (void)appendString: (OFString*)string { size_t UTF8StringLength; if (string == nil) | | < < | 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | } - (void)appendString: (OFString*)string { size_t UTF8StringLength; if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = [string UTF8StringLength]; _s->hashed = false; _s->cString = [self resizeMemory: _s->cString size: _s->cStringLength + UTF8StringLength + 1]; |
︙ | ︙ | |||
428 429 430 431 432 433 434 | isUTF8 = true; memcpy(tmp + j, buffer, 4); j += 4; break; default: | | < | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | isUTF8 = true; memcpy(tmp + j, buffer, 4); j += 4; break; default: @throw [OFInvalidEncodingException exception]; } } tmp[j] = '\0'; _s->hashed = false; _s->cString = [self resizeMemory: _s->cString |
︙ | ︙ | |||
457 458 459 460 461 462 463 | - (void)appendFormat: (OFConstantString*)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) | | < < | < | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | - (void)appendFormat: (OFConstantString*)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((UTF8StringLength = of_vasprintf(&UTF8String, [format UTF8String], arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } |
︙ | ︙ | |||
498 499 500 501 502 503 504 | for (i = 0; i < _s->cStringLength; i++) { /* ASCII */ if OF_LIKELY (!(_s->cString[i] & 0x80)) continue; /* A start byte can't happen first as we reversed everything */ if OF_UNLIKELY (_s->cString[i] & 0x40) | | < | < | < | < | < | < | 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | for (i = 0; i < _s->cStringLength; i++) { /* ASCII */ if OF_LIKELY (!(_s->cString[i] & 0x80)) continue; /* A start byte can't happen first as we reversed everything */ if OF_UNLIKELY (_s->cString[i] & 0x40) @throw [OFInvalidEncodingException exception]; /* Next byte must not be ASCII */ if OF_UNLIKELY (_s->cStringLength < i + 1 || !(_s->cString[i + 1] & 0x80)) @throw [OFInvalidEncodingException exception]; /* Next byte is the start byte */ if OF_LIKELY (_s->cString[i + 1] & 0x40) { _s->cString[i] ^= _s->cString[i + 1]; _s->cString[i + 1] ^= _s->cString[i]; _s->cString[i] ^= _s->cString[i + 1]; i++; continue; } /* Second next byte must not be ASCII */ if OF_UNLIKELY (_s->cStringLength < i + 2 || !(_s->cString[i + 2] & 0x80)) @throw [OFInvalidEncodingException exception]; /* Second next byte is the start byte */ if OF_LIKELY (_s->cString[i + 2] & 0x40) { _s->cString[i] ^= _s->cString[i + 2]; _s->cString[i + 2] ^= _s->cString[i]; _s->cString[i] ^= _s->cString[i + 2]; i += 2; continue; } /* Third next byte must not be ASCII */ if OF_UNLIKELY (_s->cStringLength < i + 3 || !(_s->cString[i + 3] & 0x80)) @throw [OFInvalidEncodingException exception]; /* Third next byte is the start byte */ if OF_LIKELY (_s->cString[i + 3] & 0x40) { _s->cString[i] ^= _s->cString[i + 3]; _s->cString[i + 3] ^= _s->cString[i]; _s->cString[i] ^= _s->cString[i + 3]; _s->cString[i + 1] ^= _s->cString[i + 2]; _s->cString[i + 2] ^= _s->cString[i + 1]; _s->cString[i + 1] ^= _s->cString[i + 2]; i += 3; continue; } /* UTF-8 does not allow more than 4 bytes per character */ @throw [OFInvalidEncodingException exception]; } } - (void)insertString: (OFString*)string atIndex: (size_t)index { size_t newCStringLength; if (index > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) index = of_string_utf8_get_position(_s->cString, index, _s->cStringLength); newCStringLength = _s->cStringLength + [string UTF8StringLength]; _s->hashed = false; |
︙ | ︙ | |||
600 601 602 603 604 605 606 | - (void)deleteCharactersInRange: (of_range_t)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) | | | 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | - (void)deleteCharactersInRange: (of_range_t)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = of_string_utf8_get_position(_s->cString, start, _s->cStringLength); end = of_string_utf8_get_position(_s->cString, end, _s->cStringLength); } |
︙ | ︙ | |||
632 633 634 635 636 637 638 | withString: (OFString*)replacement { size_t start = range.location; size_t end = range.location + range.length; size_t newCStringLength, newLength; if (range.length > SIZE_MAX - range.location || end > _s->length) | | | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | withString: (OFString*)replacement { size_t start = range.location; size_t end = range.location + range.length; size_t newCStringLength, newLength; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; newLength = _s->length - range.length + [replacement length]; if (_s->isUTF8) { start = of_string_utf8_get_position(_s->cString, start, _s->cStringLength); end = of_string_utf8_get_position(_s->cString, end, |
︙ | ︙ | |||
673 674 675 676 677 678 679 | size_t searchLength = [string UTF8StringLength]; size_t replacementLength = [replacement UTF8StringLength]; size_t i, last, newCStringLength, newLength; char *newCString; if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) | | | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | size_t searchLength = [string UTF8StringLength]; size_t replacementLength = [replacement UTF8StringLength]; size_t i, last, newCStringLength, newLength; char *newCString; if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { range.location = of_string_utf8_get_position(_s->cString, range.location, _s->cStringLength); range.length = of_string_utf8_get_position( _s->cString + range.location, range.length, _s->cStringLength - range.location); |
︙ | ︙ |