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
decode(uint32_t * state, uint32_t * codep, uint8_t byte) {
70 uint32_t type = utf8d[byte];
73 (byte & 0x3fu) | (*codep << 6) :
74 (0xff >> type) & (byte);
76 *state = utf8d[256 + *state*16 + type];
84 validator() : m_state(utf8_accept),m_codepoint(0) {}
104 template <
typename iterator_type>
105 bool decode (iterator_type begin, iterator_type end) {
106 for (iterator_type it = begin; it != end; ++it) {
110 static_cast<uint8_t>(*it)
113 if (result == utf8_reject) {
135 uint32_t m_codepoint;
145 if (!v.
decode(s.begin(),s.end())) {
154 #endif // UTF8_VALIDATOR_HPP bool decode(iterator_type begin, iterator_type end)
Advance validator state with input from an iterator pair.
uint32_t decode(uint32_t *state, uint32_t *codep, uint8_t byte)
Decode the next byte of a UTF8 sequence.
static uint8_t const utf8d[]
Lookup table for the UTF8 decode state machine.
Provides streaming UTF8 validation functionality.
bool consume(uint8_t byte)
Advance the state of the validator with the next input byte.
void reset()
Reset the validator to decode another message.
bool validate(std::string const &s)
Validate a UTF8 string.
Namespace for the WebSocket++ project.
static unsigned int const utf8_accept
State that represents a valid utf8 input sequence.
static unsigned int const utf8_reject
State that represents an invalid utf8 input sequence.
bool complete()
Return whether the input sequence ended on a valid utf8 codepoint.
validator()
Construct and initialize the validator.