41 (
'0' <= c && c <=
'9' ) ||
42 (
'a' <= c && c <=
'z' ) ||
43 (
'A' <= c && c <=
'Z' ) ||
66 (
'0' <= c && c <=
'9' ) ||
67 (
'a' <= c && c <=
'z' ) ||
68 (
'A' <= c && c <=
'Z' ) ||
101 return nullptr != std::strchr(
103 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
104 "abcdefghijklmnopqrstuvwxyz"
126 static constexpr bool
130 (
'0' <= c && c <=
'9' ) ||
131 (
'a' <= c && c <=
'z' ) ||
132 (
'A' <= c && c <=
'Z' ) ||
193 (
'0' <= c && c <=
'9' ) ||
194 (
'a' <= c && c <=
'f' ) ||
195 (
'A' <= c && c <=
'F' );
203 if(
'0' <=
c1 &&
c1 <=
'9' )
213 if(
'0' <=
c2 &&
c2 <=
'9' )
244 const char *
d = data.data();
249 const auto current_pos = [&
d, &data]()
noexcept {
return d - data.data(); };
257 "next byte from UTF-8 sequence expected at {}",
270 fmt::format(
"invalid UTF-8 sequence detected at {}",
286 "invalid escape sequence at pos {}",
current_pos() )
296 else if( Traits::ordinary_char( c ) )
306 "invalid non-escaped char with code {:#02X} at pos: {}",
315 fmt::format(
"unfinished UTF-8 sequence" )
325template<
typename Traits = restinio_default_unescape_traits >
335 [](
auto c ){ return !Traits::ordinary_char(c); } ));
340 result.assign( data.data(), data.size() );
348 if( Traits::ordinary_char( c ) )
352 result += fmt::format(
"%{:02X}", c );
360template<
typename Traits = restinio_default_unescape_traits >
366 result.reserve( data.size() );
368 auto r = impl::do_unescape_percent_encoding<Traits>(
372 throw exception_t{ r.error().giveout_description() };
389template<
typename Traits = restinio_default_unescape_traits >
395 result.reserve( data.size() );
397 auto r = impl::do_unescape_percent_encoding<Traits>(
401 return make_unexpected( std::move(r.error()) );
406template<
typename Traits = restinio_default_unescape_traits >
414 auto r = impl::do_unescape_percent_encoding<Traits>(
421 throw exception_t{ r.error().giveout_description() };
438template<
typename Traits = restinio_default_unescape_traits >
446 auto r = impl::do_unescape_percent_encoding<Traits>(
453 return make_unexpected( std::move(r.error()) );
460namespace uri_normalization
463namespace unreserved_chars
511 const char *
d =
what.data();
522 fmt::format(
"next byte from UTF-8 sequence expected at {}",
534 is_hexdigit(
d[ 1 ] ) && is_hexdigit(
d[ 2 ] ) )
536 const char ch = extract_escaped_char(
d[ 1 ],
d[ 2 ] );
539 fmt::format(
"invalid UTF-8 sequence detected at {}",
554 const char ascii_char =
static_cast<char>(symbol);
580 fmt::format(
"invalid escape sequence at pos {}",
current_pos() )
586 throw exception_t{ fmt::format(
"unfinished UTF-8 sequence" ) };
645 [&
dest](
char ch )
noexcept {
Exception class for all exceptions thrown by RESTinio.
Type that indicates a failure of unescaping of percent-encoded symbols.
RESTINIO_NODISCARD const std::string & description() const noexcept
Get a reference to the description of the failure.
std::string m_description
Description of a failure.
RESTINIO_NODISCARD std::string giveout_description() noexcept
Get out the value of the description of the failure.
unescape_percent_encoding_failure_t(std::string description)
Helper class for checking UTF-8 byte sequence during parsing URI or incoming byte stream.
#define RESTINIO_NODISCARD
A special wrapper around fmtlib include files.
RESTINIO_NODISCARD expected_t< unescape_percent_encoding_success_t, unescape_percent_encoding_failure_t > do_unescape_percent_encoding(const string_view_t data, Chars_Collector &&collector)
The actual implementation of unescape-percent-encoding procedure.
char extract_escaped_char(char c1, char c2)
RESTINIO_NODISCARD constexpr bool is_unreserved_char(const char ch) noexcept
Is this symbol a part of unreserved set?
void run_normalization_algo(string_view_t what, One_Byte_Handler &&one_byte_handler, Three_Byte_Handler &&three_byte_handler)
Internal helper to perform the main logic of enumeration of symbols in URI.
void normalize_to(string_view_t what, char *dest)
Perform normalization of URI value.
RESTINIO_NODISCARD std::size_t estimate_required_capacity(string_view_t what)
Calculate the size of a buffer to hold normalized value of a URI.
RESTINIO_NODISCARD expected_t< std::string, unescape_percent_encoding_failure_t > try_unescape_percent_encoding(const string_view_t data)
Helper function for unescaping percent-encoded string.
RESTINIO_NODISCARD expected_t< std::size_t, unescape_percent_encoding_failure_t > try_inplace_unescape_percent_encoding(char *data, std::size_t size)
Helper function for unescaping percent-encoded string inplace.
RESTINIO_NODISCARD std::size_t inplace_unescape_percent_encoding(char *data, std::size_t size)
RESTINIO_NODISCARD std::string unescape_percent_encoding(const string_view_t data)
RESTINIO_NODISCARD std::string escape_percent_encoding(const string_view_t data)
Percent encoding.
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
nonstd::string_view string_view_t
nonstd::expected< T, E > expected_t
The traits for escaping and unexcaping symbols in JavaScript-compatible mode.
static constexpr bool ordinary_char(char c) noexcept
Traits for escaping and unescaping symbols in a query string in very relaxed mode.
static bool ordinary_char(char c) noexcept
The default traits for escaping and unexcaping symbols in a query string.
static constexpr bool ordinary_char(char c) noexcept
Type that indicates that unescaping of percent-encoded symbols completed successfully.
An implementation of checker for UTF-8 sequences.