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
RESTINIO_NODISCARD bool | process_byte (std::uint8_t byte) noexcept
RESTINIO_NODISCARD bool | finalized () const noexcept
void | reset () noexcept
RESTINIO_NODISCARD 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

strong private

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()

RESTINIO_NODISCARD std::uint32_t restinio::utils::utf8_checker_t::current_symbol | ( |  | ) | const

inline noexcept

Get the collected value of the current symbol.

Note
  It returns the actual value only if:

- some bytes were successfully feed into process_byte();
- finalized() returns `true`.

Definition at line 342 of file utf8_checker.hpp.

## finalized()

RESTINIO_NODISCARD bool restinio::utils::utf8_checker_t::finalized | ( |  | ) | const

inline noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

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 | ) |

inline private noexcept

Definition at line 158 of file utf8_checker.hpp.

## process_byte()

RESTINIO_NODISCARD bool restinio::utils::utf8_checker_t::process_byte | ( | std::uint8_t | byte | ) |

inline noexcept

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

  true | if the sequence is still valid and the next byte can be given to the next call to process_byte().
  false | if 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 | ( |  | ) |

inline noexcept

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:

- restinio/utils/utf8_checker.hpp