Differences From Artifact [3f21e1777e]:
- File
src/OFMutableString_UTF8.m
— part of check-in
[f7576a66ce]
at
2012-06-06 13:47:52
on branch trunk
— Slightly change the memory management API.
Also fix a bug where OFBigDataArray would waste memory. (user: js, size: 17311) [annotate] [blame] [check-ins using] [more...]
To Artifact [ccd236b694]:
- File src/OFMutableString_UTF8.m — part of check-in [11d3d69a22] at 2012-06-10 13:28:05 on branch trunk — More API improvements. (user: js, size: 17306) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
65 66 67 68 69 70 71 | if ((t = table[0][*p]) != 0) *p = t; return; } unicodeLen = [self length]; | | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | if ((t = table[0][*p]) != 0) *p = t; return; } unicodeLen = [self length]; unicodeString = [self allocMemoryWithSize: sizeof(of_unichar_t) count: unicodeLen]; i = j = 0; newCStringLength = 0; while (i < s->cStringLength) { cLen = of_string_utf8_to_unicode(s->cString + i, s->cStringLength - i, &c); |
︙ | ︙ | |||
174 175 176 177 178 179 180 | if (length == oldLength) { memcpy(s->cString + index, buffer, length); return; } if (length > oldLength) { s->cString = [self resizeMemory: s->cString | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | if (length == oldLength) { memcpy(s->cString + index, buffer, length); return; } if (length > oldLength) { s->cString = [self resizeMemory: s->cString size: s->cStringLength - oldLength + length + 1]; memmove(s->cString + index + length, s->cString + index + oldLength, s->cStringLength - index - oldLength); memcpy(s->cString + index, buffer, length); s->cStringLength -= oldLength; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | s->cStringLength -= oldLength; s->cStringLength += length; s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | s->cStringLength -= oldLength; s->cStringLength += length; s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } return; } |
︙ | ︙ | |||
235 236 237 238 239 240 241 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1); s->cStringLength += UTF8StringLength; s->length += length; } |
︙ | ︙ | |||
263 264 265 266 267 268 269 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength); s->cStringLength += UTF8StringLength; s->length += length; s->cString[s->cStringLength] = 0; |
︙ | ︙ | |||
310 311 312 313 314 315 316 | @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; UTF8StringLength = [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; UTF8StringLength = [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, [string UTF8String], UTF8StringLength); s->cStringLength += UTF8StringLength; s->length += [string length]; |
︙ | ︙ | |||
449 450 451 452 453 454 455 | if (s->UTF8) index = of_string_index_to_position(s->cString, index, s->cStringLength); newCStringLength = s->cStringLength + [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | if (s->UTF8) index = of_string_index_to_position(s->cString, index, s->cStringLength); newCStringLength = s->cStringLength + [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: newCStringLength + 1]; memmove(s->cString + index + [string UTF8StringLength], s->cString + index, s->cStringLength - index); memcpy(s->cString + index, [string UTF8String], [string UTF8StringLength]); s->cString[newCStringLength] = '\0'; |
︙ | ︙ | |||
492 493 494 495 496 497 498 | memmove(s->cString + start, s->cString + end, s->cStringLength - end); s->cStringLength -= end - start; s->cString[s->cStringLength] = 0; @try { s->cString = [self resizeMemory: s->cString | | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | memmove(s->cString + start, s->cString + end, s->cStringLength - end); s->cStringLength -= end - start; s->cString[s->cStringLength] = 0; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString*)replacement |
︙ | ︙ | |||
521 522 523 524 525 526 527 | s->cStringLength); } newCStringLength = s->cStringLength - (end - start) + [replacement UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | s->cStringLength); } newCStringLength = s->cStringLength - (end - start) + [replacement UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: newCStringLength + 1]; memmove(s->cString + start + [replacement UTF8StringLength], s->cString + end, s->cStringLength - end); memcpy(s->cString + start, [replacement UTF8String], [replacement UTF8StringLength]); s->cString[newCStringLength] = '\0'; |
︙ | ︙ | |||
568 569 570 571 572 573 574 | for (i = range.start, last = 0; i <= range.length - searchLength; i++) { if (memcmp(s->cString + i, searchString, searchLength)) continue; @try { newCString = [self resizeMemory: newCString | | | < | | | 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 598 599 600 601 602 603 | for (i = range.start, last = 0; i <= range.length - searchLength; i++) { if (memcmp(s->cString + i, searchString, searchLength)) continue; @try { newCString = [self resizeMemory: newCString size: newCStringLength + i - last + replacementLength + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } memcpy(newCString + newCStringLength, s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, replacementString, replacementLength); newCStringLength += i - last + replacementLength; newLength = newLength - [string length] + [replacement length]; i += searchLength - 1; last = i + 1; } @try { newCString = [self resizeMemory: newCString size: newCStringLength + s->cStringLength - last + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } memcpy(newCString + newCStringLength, s->cString + last, s->cStringLength - last); newCStringLength += s->cStringLength - last; |
︙ | ︙ | |||
626 627 628 629 630 631 632 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteTrailingWhitespaces { |
︙ | ︙ | |||
654 655 656 657 658 659 660 | } s->cStringLength -= d; s->length -= d; @try { s->cString = [self resizeMemory: s->cString | | | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | } s->cStringLength -= d; s->length -= d; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteEnclosingWhitespaces { |
︙ | ︙ | |||
694 695 696 697 698 699 700 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)makeImmutable { isa = [OFString_UTF8 class]; } @end |