Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
utf8_decoder Struct Reference

Public Types

typedef uint8_t type

Static Public Member Functions

template<typename Traits>
static Traits::value_type process (const uint8_t *data, size_t size, typename Traits::value_type result, Traits)

Detailed Description

Definition at line 1636 of file pugixml.cc.

Member Typedef Documentation

◆ type

typedef uint8_t utf8_decoder::type

Definition at line 1638 of file pugixml.cc.

Member Function Documentation

◆ process()

template<typename Traits>
Traits::value_type utf8_decoder::process ( const uint8_t * data,
size_t size,
typename Traits::value_type result,
Traits  )
inlinestatic

Definition at line 1640 of file pugixml.cc.

1641 {
1642 const uint8_t utf8_byte_mask = 0x3f;
1643
1644 while (size)
1645 {
1646 uint8_t lead = *data;
1647
1648 // 0xxxxxxx -> U+0000..U+007F
1649 if (lead < 0x80)
1650 {
1651 result = Traits::low(result, lead);
1652 data += 1;
1653 size -= 1;
1654
1655 // process aligned single-byte (ascii) blocks
1656 if ((reinterpret_cast<uintptr_t>(data) & 3) == 0)
1657 {
1658 // round-trip through void* to silence 'cast increases required alignment of target type' warnings
1659 while (size >= 4 && (*static_cast<const uint32_t*>(static_cast<const void*>(data)) & 0x80808080) == 0)
1660 {
1661 result = Traits::low(result, data[0]);
1662 result = Traits::low(result, data[1]);
1663 result = Traits::low(result, data[2]);
1664 result = Traits::low(result, data[3]);
1665 data += 4;
1666 size -= 4;
1667 }
1668 }
1669 }
1670 // 110xxxxx -> U+0080..U+07FF
1671 else if (static_cast<unsigned int>(lead - 0xC0) < 0x20 && size >= 2 && (data[1] & 0xc0) == 0x80)
1672 {
1673 result = Traits::low(result, ((lead & ~0xC0) << 6) | (data[1] & utf8_byte_mask));
1674 data += 2;
1675 size -= 2;
1676 }
1677 // 1110xxxx -> U+0800-U+FFFF
1678 else if (static_cast<unsigned int>(lead - 0xE0) < 0x10 && size >= 3 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80)
1679 {
1680 result = Traits::low(result, ((lead & ~0xE0) << 12) | ((data[1] & utf8_byte_mask) << 6) | (data[2] & utf8_byte_mask));
1681 data += 3;
1682 size -= 3;
1683 }
1684 // 11110xxx -> U+10000..U+10FFFF
1685 else if (static_cast<unsigned int>(lead - 0xF0) < 0x08 && size >= 4 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80 && (data[3] & 0xc0) == 0x80)
1686 {
1687 result = Traits::high(result, ((lead & ~0xF0) << 18) | ((data[1] & utf8_byte_mask) << 12) | ((data[2] & utf8_byte_mask) << 6) | (data[3] & utf8_byte_mask));
1688 data += 4;
1689 size -= 4;
1690 }
1691 // 10xxxxxx or 11111xxx -> invalid
1692 else
1693 {
1694 data += 1;
1695 size -= 1;
1696 }
1697 }
1698
1699 return result;
1700 }

Referenced by as_wide_impl().


The documentation for this struct was generated from the following file: