Overview
Comment: | Fix of_unicode_string_length() and actually use it. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
44bb6eeef33bbc381f780e53caca0c8b |
User & Date: | js on 2011-05-14 22:38:52 |
Other Links: | manifest | tags |
Context
2011-05-14
| ||
23:25 | Correctly check the length in of_string_check_utf8. check-in: 55368ab28a user: js tags: trunk | |
22:38 | Fix of_unicode_string_length() and actually use it. check-in: 44bb6eeef3 user: js tags: trunk | |
19:48 | Ignore whitespaces around the root element in -[initWithXMLString]. check-in: 12a8ac4cb3 user: js tags: trunk | |
Changes
Modified src/OFString.m from [47a649e523] to [eb8762e376].
︙ | ︙ | |||
246 247 248 249 250 251 252 | } size_t of_unicode_string_length(const of_unichar_t *string) { const of_unichar_t *string_ = string; | | | | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | } size_t of_unicode_string_length(const of_unichar_t *string) { const of_unichar_t *string_ = string; while (*string_ != 0) string_++; return (size_t)(string_ - string); } @implementation OFString + string { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
558 559 560 561 562 563 564 | - initWithUnicodeString: (of_unichar_t*)string_ length: (size_t)length_ { self = [super init]; @try { char buffer[4]; | | | < < | < | | < < | | < < < | | < < < | | < < < | | | > | | > > > > > > | < | 558 559 560 561 562 563 564 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 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 | - initWithUnicodeString: (of_unichar_t*)string_ length: (size_t)length_ { self = [super init]; @try { char buffer[4]; size_t i, j = 0; BOOL swap = NO; if (*string_ == 0xFEFF) { string_++; length_--; } if (*string_ == 0xFFFE0000) { swap = YES; string_++; length_--; } length = length_; string = [self allocMemoryWithSize: (length * 4) + 1]; for (i = 0; i < length_; i++) { size_t characterLen = of_string_unicode_to_utf8( (swap ? of_bswap32(string_[i]) : string_[i]), buffer); switch (characterLen) { case 1: string[j++] = buffer[0]; break; case 2: isUTF8 = YES; length++; memcpy(string + j, buffer, 2); j += 2; break; case 3: isUTF8 = YES; length += 2; memcpy(string + j, buffer, 3); j += 3; break; case 4: isUTF8 = YES; length += 3; memcpy(string + j, buffer, 4); j += 4; break; default: @throw [OFInvalidEncodingException newWithClass: isa]; } } string[j] = '\0'; @try { string = [self resizeMemory: string toSize: length + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ [e release]; } } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |