| 612 | /* --------------------------------------------------------------------- */ |
| 613 | |
| 614 | static ConversionResult ConvertUTF8toUTF32Impl( |
| 615 | const UTF8** sourceStart, const UTF8* sourceEnd, |
| 616 | UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags, |
| 617 | Boolean InputIsPartial) { |
| 618 | ConversionResult result = conversionOK; |
| 619 | const UTF8* source = *sourceStart; |
| 620 | UTF32* target = *targetStart; |
| 621 | while (source < sourceEnd) { |
| 622 | UTF32 ch = 0; |
| 623 | unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; |
| 624 | if (extraBytesToRead >= sourceEnd - source) { |
| 625 | if (flags == strictConversion || InputIsPartial) { |
| 626 | result = sourceExhausted; |
| 627 | break; |
| 628 | } else { |
| 629 | result = sourceIllegal; |
| 630 | |
| 631 | /* |
| 632 | * Replace the maximal subpart of ill-formed sequence with |
| 633 | * replacement character. |
| 634 | */ |
| 635 | source += findMaximalSubpartOfIllFormedUTF8Sequence(source, |
| 636 | sourceEnd); |
| 637 | *target++ = UNI_REPLACEMENT_CHAR; |
| 638 | continue; |
| 639 | } |
| 640 | } |
| 641 | if (target >= targetEnd) { |
| 642 | result = targetExhausted; break; |
| 643 | } |
| 644 | |
| 645 | /* Do this check whether lenient or strict */ |
| 646 | if (!isLegalUTF8(source, extraBytesToRead+1)) { |
| 647 | result = sourceIllegal; |
| 648 | if (flags == strictConversion) { |
| 649 | /* Abort conversion. */ |
| 650 | break; |
| 651 | } else { |
| 652 | /* |
| 653 | * Replace the maximal subpart of ill-formed sequence with |
| 654 | * replacement character. |
| 655 | */ |
| 656 | source += findMaximalSubpartOfIllFormedUTF8Sequence(source, |
| 657 | sourceEnd); |
| 658 | *target++ = UNI_REPLACEMENT_CHAR; |
| 659 | continue; |
| 660 | } |
| 661 | } |
| 662 | /* |
| 663 | * The cases all fall through. See "Note A" below. |
| 664 | */ |
| 665 | switch (extraBytesToRead) { |
| 666 | case 5: ch += *source++; ch <<= 6; |
| 667 | case 4: ch += *source++; ch <<= 6; |
| 668 | case 3: ch += *source++; ch <<= 6; |
| 669 | case 2: ch += *source++; ch <<= 6; |
| 670 | case 1: ch += *source++; ch <<= 6; |
| 671 | case 0: ch += *source++; |
no test coverage detected