Loading...
Searching...
No Matches
target_path_holder.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/utils/percent_encoding.hpp>
#include <restinio/string_view.hpp>
#include <memory>
namespace restinio
{
namespace router
{
namespace impl
{
//
// target_path_holder_t
//
class target_path_holder_t
{
public:
using data_t = std::unique_ptr<char[]>;
target_path_holder_t( string_view_t original_path )
: m_size{ restinio::utils::uri_normalization::
unreserved_chars::estimate_required_capacity( original_path ) }
{
m_data.reset( new char[ m_size ] );
if( m_size != original_path.size() )
// Transformation is actually needed.
restinio::utils::uri_normalization::unreserved_chars::
normalize_to( original_path, m_data.get() );
else
// Just copy original value to the destination.
std::copy(
original_path.begin(), original_path.end(),
m_data.get() );
}
RESTINIO_NODISCARD
string_view_t
view() const noexcept
{
return { m_data.get(), m_size };
}
RESTINIO_NODISCARD
data_t
giveout_data() noexcept
{
return std::move(m_data);
}
private:
data_t m_data;
std::size_t m_size;
};
} /* namespace impl */
} /* namespace router */
} /* namespace restinio */
restinio::router::impl::target_path_holder_t
Helper class for holding a unique instance of char array with target_path value.
Definition: target_path_holder.hpp:46
restinio::router::impl::target_path_holder_t::view
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
Definition: target_path_holder.hpp:86
restinio::router::impl::target_path_holder_t::m_data
data_t m_data
Actual data with target_path.
Definition: target_path_holder.hpp:110
restinio::router::impl::target_path_holder_t::target_path_holder_t
target_path_holder_t(string_view_t original_path)
Initializing constructor.
Definition: target_path_holder.hpp:62
restinio::router::impl::target_path_holder_t::m_size
std::size_t m_size
The length of target_path.
Definition: target_path_holder.hpp:112
restinio::router::impl::target_path_holder_t::giveout_data
RESTINIO_NODISCARD data_t giveout_data() noexcept
Give out the value from holder.
Definition: target_path_holder.hpp:99
restinio::router::impl::target_path_holder_t::data_t
std::unique_ptr< char[]> data_t
Definition: target_path_holder.hpp:48
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:36
restinio::utils::uri_normalization::unreserved_chars::normalize_to
void normalize_to(string_view_t what, char *dest)
Perform normalization of URI value.
Definition: percent_encoding.hpp:654
restinio
Definition: asio_include.hpp:21
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
percent_encoding.hpp
string_view.hpp
const
#define const
Definition: zconf.h:230