utf_decoder< Traits, opt_swap > Struct Template Reference

## Static Public Member Functions

static Traits::value_type | decode_utf8_block (const uint8_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_utf16_block (const uint16_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_utf32_block (const uint32_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_latin1_block (const uint8_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_wchar_block_impl (const uint16_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_wchar_block_impl (const uint32_t *data, size_t size, typename Traits::value_type result)
static Traits::value_type | decode_wchar_block (const wchar_t *data, size_t size, typename Traits::value_type result)

## Detailed Description

### template<typename Traits, typename opt_swap = opt_false>
struct utf_decoder< Traits, opt_swap >

Definition at line 952 of file pugixml.cpp.

## Member Function Documentation

## decode_latin1_block()

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_latin1_block | ( | const uint8_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1085 of file pugixml.cpp.

{
for (size_t i = 0; i < size; ++i)
{
result = Traits::low(result, data[i]);
}
return result;
}

Referenced by convert_buffer_latin1().

## decode_utf16_block()

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_utf16_block | ( | const uint16_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1016 of file pugixml.cpp.

{
const uint16_t* end = data + size;
while (data < end)
{
unsigned int lead = opt_swap::value ? endian_swap(*data) : *data;
// U+0000..U+D7FF
if (lead < 0xD800)
{
result = Traits::low(result, lead);
data += 1;
}
// U+E000..U+FFFF
else if (static_cast<unsigned int>(lead - 0xE000) < 0x2000)
{
result = Traits::low(result, lead);
data += 1;
}
// surrogate pair lead
else if (static_cast<unsigned int>(lead - 0xD800) < 0x400 && data + 1 < end)
{
uint16_t next = opt_swap::value ? endian_swap(data[1]) : data[1];
if (static_cast<unsigned int>(next - 0xDC00) < 0x400)
{
result = Traits::high(result, 0x10000 + ((lead & 0x3ff) << 10) + (next & 0x3ff));
data += 2;
}
else
{
data += 1;
}
}
else
{
data += 1;
}
}
return result;
}
endian_swap
PUGI__NS_END PUGI__NS_BEGIN uint16_t endian_swap(uint16_t value)
Definition: pugixml.cpp:752
uint16_t
unsigned short uint16_t
Definition: stdint_msvc.h:80

References endian_swap().

Referenced by convert_buffer_utf16(), and utf_decoder< Traits, opt_swap >::decode_wchar_block_impl().

## decode_utf32_block()

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_utf32_block | ( | const uint32_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1060 of file pugixml.cpp.

{
const uint32_t* end = data + size;
while (data < end)
{
uint32_t lead = opt_swap::value ? endian_swap(*data) : *data;
// U+0000..U+FFFF
if (lead < 0x10000)
{
result = Traits::low(result, lead);
data += 1;
}
// U+10000..U+10FFFF
else
{
result = Traits::high(result, lead);
data += 1;
}
}
return result;
}
uint32_t
unsigned int uint32_t
Definition: stdint_msvc.h:81

References endian_swap().

Referenced by convert_buffer_utf32(), and utf_decoder< Traits, opt_swap >::decode_wchar_block_impl().

## decode_utf8_block()

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_utf8_block | ( | const uint8_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 954 of file pugixml.cpp.

{
const uint8_t utf8_byte_mask = 0x3f;
while (size)
{
uint8_t lead = *data;
// 0xxxxxxx -> U+0000..U+007F
if (lead < 0x80)
{
result = Traits::low(result, lead);
data += 1;
size -= 1;
// process aligned single-byte (ascii) blocks
if ((reinterpret_cast<uintptr_t>(data) & 3) == 0)
{
// round-trip through void* to silence 'cast increases required alignment of target type' warnings
while (size >= 4 && (*static_cast<const uint32_t*>(static_cast<const void*>(data)) & 0x80808080) == 0)
{
result = Traits::low(result, data[0]);
result = Traits::low(result, data[1]);
result = Traits::low(result, data[2]);
result = Traits::low(result, data[3]);
data += 4;
size -= 4;
}
}
}
// 110xxxxx -> U+0080..U+07FF
else if (static_cast<unsigned int>(lead - 0xC0) < 0x20 && size >= 2 && (data[1] & 0xc0) == 0x80)
{
result = Traits::low(result, ((lead & ~0xC0) << 6) | (data[1] & utf8_byte_mask));
data += 2;
size -= 2;
}
// 1110xxxx -> U+0800-U+FFFF
else if (static_cast<unsigned int>(lead - 0xE0) < 0x10 && size >= 3 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80)
{
result = Traits::low(result, ((lead & ~0xE0) << 12) | ((data[1] & utf8_byte_mask) << 6) | (data[2] & utf8_byte_mask));
data += 3;
size -= 3;
}
// 11110xxx -> U+10000..U+10FFFF
else if (static_cast<unsigned int>(lead - 0xF0) < 0x08 && size >= 4 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80 && (data[3] & 0xc0) == 0x80)
{
result = Traits::high(result, ((lead & ~0xF0) << 18) | ((data[1] & utf8_byte_mask) << 12) | ((data[2] & utf8_byte_mask) << 6) | (data[3] & utf8_byte_mask));
data += 4;
size -= 4;
}
// 10xxxxxx or 11111xxx -> invalid
else
{
data += 1;
size -= 1;
}
}
return result;
}
uintptr_t
_W64 unsigned int uintptr_t
Definition: stdint_msvc.h:120
uint8_t
unsigned char uint8_t
Definition: stdint_msvc.h:79

Referenced by as_wide_impl(), and convert_buffer_output().

## decode_wchar_block()

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_wchar_block | ( | const wchar_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1105 of file pugixml.cpp.

{
return decode_wchar_block_impl(reinterpret_cast<const wchar_selector<sizeof(wchar_t)>::type*>(data), size, result);
}
utf_decoder::decode_wchar_block_impl
static Traits::value_type decode_wchar_block_impl(const uint16_t *data, size_t size, typename Traits::value_type result)
Definition: pugixml.cpp:1095
wchar_selector
Definition: pugixml.cpp:933

References utf_decoder< Traits, opt_swap >::decode_wchar_block_impl().

Referenced by as_utf8_begin(), and as_utf8_end().

## decode_wchar_block_impl() [1/2]

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_wchar_block_impl | ( | const uint16_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1095 of file pugixml.cpp.

{
return decode_utf16_block(data, size, result);
}
utf_decoder::decode_utf16_block
static Traits::value_type decode_utf16_block(const uint16_t *data, size_t size, typename Traits::value_type result)
Definition: pugixml.cpp:1016

References utf_decoder< Traits, opt_swap >::decode_utf16_block().

Referenced by utf_decoder< Traits, opt_swap >::decode_wchar_block().

## decode_wchar_block_impl() [2/2]

template<typename Traits , typename opt_swap = opt_false>

static Traits::value_type utf_decoder< Traits, opt_swap >::decode_wchar_block_impl | ( | const uint32_t * | data,
|  | size_t | size,
|  | typename Traits::value_type | result
| ) |  |

inline static

Definition at line 1100 of file pugixml.cpp.

{
return decode_utf32_block(data, size, result);
}
utf_decoder::decode_utf32_block
static Traits::value_type decode_utf32_block(const uint32_t *data, size_t size, typename Traits::value_type result)
Definition: pugixml.cpp:1060

References utf_decoder< Traits, opt_swap >::decode_utf32_block().

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

- pugixml.cpp