Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created January 20, 2020 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/0c4f7d4b80e980c800554d44a6e93c21 to your computer and use it in GitHub Desktop.
Save vinniefalco/0c4f7d4b80e980c800554d44a6e93c21 to your computer and use it in GitHub Desktop.
namespace url {
class basic_value
{
public:
basic_value() = default;
// return the hostname
string_view
encoded_hostname() const noexcept
{
if(size() == 0)
return {};
return {
data(), size() };
}
// set the hostname
basic_value&
set_hostname( string_view s )
{
resize( 0 );
resize( s.size() );
std::copy( s.begin(), s.end(), data() );
return *this;
}
protected:
virtual char* data() noexcept = 0;
virtual char const* data() const noexcept = 0;
virtual std::size_t size() const noexcept = 0;
virtual void resize(std::size_t n) = 0;
};
template<class Allocator>
class dynamic_value : public basic_value
{
Allocator a_;
...
};
template<std::size_t N>
class static_value : public basic_value
{
char buf_[N+1]; // for the null
};
using value = dynamic_value<std::allocator<char>>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment