Differences From Artifact [5a1fe9d9fc]:
- File
src/OFString_UTF8.m
— part of check-in
[545b6f740e]
at
2013-01-13 13:07:52
on branch trunk
— Add of_char{16,32}_t.
For ObjC++, these are defined to char{16,32}_t if C++11 is used. This
means passing e.g. a C++11 UTF-16 string to -[initWithUTF16String:]
works without a warning.For C11, this is not necessary, as char{16,32}_t are just typedef'd to
uint_least{16,32}_t in <uchar.h> and thus compatible to the definition
of of_char{16,32}_t. The reason for not defining of_char{16,32}_t to
char{16,32}_t when using C11 is that <uchar.h> might be missing and that
char{16,32}_t are not required to be UTF-{16,32}, whereas in C++, they
are required to be UTF-{16,32}. (user: js, size: 30912) [annotate] [blame] [check-ins using]
To Artifact [17c27fdf19]:
- File src/OFString_UTF8.m — part of check-in [7694d37135] at 2013-01-16 14:27:07 on branch trunk — OFString: Add -[getCString:maxLength:encoding:]. (user: js, size: 30924) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
413 414 415 416 417 418 419 420 | s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; | > > | < < < < < < < < < < < < | | | 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 440 | s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode(characters[i], buffer); switch (len) { case 1: s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: s->isUTF8 = YES; memcpy(s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } |
︙ | ︙ | |||
484 485 486 487 488 489 490 | string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; | < | | 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; of_unichar_t character = (swap ? OF_BSWAP16(string[i]) : string[i]); size_t len; /* Missing high surrogate */ if ((character & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; if ((character & 0xFC00) == 0xD800) { |
︙ | ︙ | |||
518 519 520 521 522 523 524 | @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; | < | | < < < < < < < < < < < < < < < | | > | | 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 | @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; s->length--; } len = of_string_utf8_encode(character, buffer); switch (len) { case 1: s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: s->isUTF8 = YES; memcpy(s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } s->cString[j] = '\0'; s->cStringLength = j; @try { s->cString = [self resizeMemory: s->cString size: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
601 602 603 604 605 606 607 | s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; | | | < < < < < < < < < < < < | | | 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 | s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode( (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); switch (len) { case 1: s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: s->isUTF8 = YES; memcpy(s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } |
︙ | ︙ | |||
771 772 773 774 775 776 777 778 779 780 781 | - (void)dealloc { if (s != NULL && s->freeWhenDone != NULL) free(s->freeWhenDone); [super dealloc]; } - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { | > > > > > > > > > > > > > > > > > > > > > > > > > < < | > | 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 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 | - (void)dealloc { if (s != NULL && s->freeWhenDone != NULL) free(s->freeWhenDone); [super dealloc]; } - (size_t)getCString: (char*)cString maxLength: (size_t)maxLength encoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: if (s->isUTF8) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: if (s->cStringLength + 1 > maxLength) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; memcpy(cString, s->cString, s->cStringLength + 1); return s->cStringLength; default: return [super getCString: cString maxLength: maxLength encoding: encoding]; } } - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: if (s->isUTF8) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: return s->cString; default: return [super cStringWithEncoding: encoding]; } } - (const char*)UTF8String |
︙ | ︙ |