Created
January 20, 2020 17:58
-
-
Save vinniefalco/0c4f7d4b80e980c800554d44a6e93c21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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