RESTinio
Loading...
Searching...
No Matches
restinio::utils::utf8_checker_t Class Reference

Helper class for checking UTF-8 byte sequence during parsing URI or incoming byte stream. More...

#include <utf8_checker.hpp>

Public Member Functions

 utf8_checker_t ()=default
bool process_byte (std::uint8_t byte) noexcept
bool finalized () const noexcept
void reset () noexcept
std::uint32_t current_symbol () const noexcept

Private Types

enum class  state_t {
  wait_first_byte , wait_second_of_two , wait_second_of_three , wait_second_of_four ,
  wait_third_of_three , wait_third_of_four , wait_fourth_of_four , invalid
}
 Enumeration of all possible checker states. More...

Private Member Functions

void on_first_byte (std::uint8_t byte) noexcept
void on_second_of_two (std::uint8_t byte) noexcept
void on_second_of_three (std::uint8_t byte) noexcept
void on_second_of_four (std::uint8_t byte) noexcept
void on_third_of_three (std::uint8_t byte) noexcept
void on_third_of_four (std::uint8_t byte) noexcept
void on_fourth_of_four (std::uint8_t byte) noexcept

Private Attributes

std::uint32_t m_current_symbol = 0u
 The current UNICODE symbol.
state_t m_state { state_t::wait_first_byte }
 The current state of the checker.

Detailed Description

Helper class for checking UTF-8 byte sequence during parsing URI or incoming byte stream.

Definition at line 32 of file utf8_checker.hpp.

Member Enumeration Documentation

◆ state_t

enum class restinio::utils::utf8_checker_t::state_t
strongprivate

Enumeration of all possible checker states.

Enumerator
wait_first_byte 
wait_second_of_two 
wait_second_of_three 
wait_second_of_four 
wait_third_of_three 
wait_third_of_four 
wait_fourth_of_four 
invalid 

Definition at line 35 of file utf8_checker.hpp.

Constructor & Destructor Documentation

◆ utf8_checker_t()

restinio::utils::utf8_checker_t::utf8_checker_t ( )
default

Member Function Documentation

◆ current_symbol()

std::uint32_t restinio::utils::utf8_checker_t::current_symbol ( ) const
inlinenodiscardnoexcept

Get the collected value of the current symbol.

Note
It returns the actual value only if:

Definition at line 342 of file utf8_checker.hpp.

◆ finalized()

bool restinio::utils::utf8_checker_t::finalized ( ) const
inlinenodiscardnoexcept
Returns
true if the current sequence finalized.

Definition at line 316 of file utf8_checker.hpp.

◆ on_first_byte()

void restinio::utils::utf8_checker_t::on_first_byte ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 59 of file utf8_checker.hpp.

◆ on_fourth_of_four()

void restinio::utils::utf8_checker_t::on_fourth_of_four ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 204 of file utf8_checker.hpp.

◆ on_second_of_four()

void restinio::utils::utf8_checker_t::on_second_of_four ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 142 of file utf8_checker.hpp.

◆ on_second_of_three()

void restinio::utils::utf8_checker_t::on_second_of_three ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 126 of file utf8_checker.hpp.

◆ on_second_of_two()

void restinio::utils::utf8_checker_t::on_second_of_two ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 99 of file utf8_checker.hpp.

◆ on_third_of_four()

void restinio::utils::utf8_checker_t::on_third_of_four ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 188 of file utf8_checker.hpp.

◆ on_third_of_three()

void restinio::utils::utf8_checker_t::on_third_of_three ( std::uint8_t byte)
inlineprivatenoexcept

Definition at line 158 of file utf8_checker.hpp.

◆ process_byte()

bool restinio::utils::utf8_checker_t::process_byte ( std::uint8_t byte)
inlinenodiscardnoexcept

Checks another byte.

Note
The actual value of the current symbol can be obtained only if process_byte() returns true and the subsequent call to finalized() returns true:
utf8checker_t checker;
for( const auto ch : some_string )
{
if( checker.process_byte() )
{
if( checker.finalized() )
process_unicode_symbol( checker.current_symbol() );
}
else
{
... // Invalid sequence found!
break;
}
}
Return values
trueif the sequence is still valid and the next byte can be given to the next call to process_byte().
falseif the sequence is invalid an there is no sense to continue call process_byte().

Definition at line 271 of file utf8_checker.hpp.

◆ reset()

void restinio::utils::utf8_checker_t::reset ( )
inlinenoexcept

Return the object into the initial state.

Definition at line 325 of file utf8_checker.hpp.

Member Data Documentation

◆ m_current_symbol

std::uint32_t restinio::utils::utf8_checker_t::m_current_symbol = 0u
private

The current UNICODE symbol.

Contains a valid value only if some bytes were successfully processed by process_byte() and the current state is wait_first_byte.

Definition at line 53 of file utf8_checker.hpp.

◆ m_state

state_t restinio::utils::utf8_checker_t::m_state { state_t::wait_first_byte }
private

The current state of the checker.

Definition at line 56 of file utf8_checker.hpp.


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