diff --git a/doc/qbk/0.main.qbk b/doc/qbk/0.main.qbk
index c26b99b1..71fbc454 100644
--- a/doc/qbk/0.main.qbk
+++ b/doc/qbk/0.main.qbk
@@ -53,7 +53,7 @@
[def __result__ [link url.ref.boost__urls__result `result`]]
[def __static_pool__ [link url.ref.boost__urls__static_pool `static_pool`]]
[def __static_url__ [link url.ref.boost__urls__static_url `static_url`]]
-[def __string_value__ [link url.ref.boost__urls__string_value `string_value`]]
+[def __const_string__ [link url.ref.boost__urls__const_string `const_string`]]
[def __string_view__ [link url.ref.boost__urls__string_view `string_view`]]
[def __url__ [link url.ref.boost__urls__url `url`]]
[def __url_view__ [link url.ref.boost__urls__url_view `url_view`]]
diff --git a/doc/qbk/1.1.quicklook.qbk b/doc/qbk/1.1.quicklook.qbk
index e86b86ea..e1dcf960 100644
--- a/doc/qbk/1.1.quicklook.qbk
+++ b/doc/qbk/1.1.quicklook.qbk
@@ -69,7 +69,7 @@ call the same function without the word encoded:
```
]]]
-The function `query` returns a __string_value__, which is a library type
+The function `query` returns a __const_string__, which is a library type
that models a read-only string with ownership of the underlying buffer,
which uses a type-erased allocator. All functions which return string
values accept an optional __Allocator__ parameter when when omitted,
diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml
index 274865d2..c2782d47 100644
--- a/doc/qbk/quickref.xml
+++ b/doc/qbk/quickref.xml
@@ -73,7 +73,7 @@
error_code
error_condition
result
- string_value
+ const_string
string_view
system_error
diff --git a/include/boost/url/authority_view.hpp b/include/boost/url/authority_view.hpp
index ad4514d3..a87b6b4d 100644
--- a/include/boost/url/authority_view.hpp
+++ b/include/boost/url/authority_view.hpp
@@ -522,7 +522,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -536,7 +536,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
userinfo(
Allocator const& a = {}) const
{
@@ -614,7 +614,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -630,7 +630,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
user(
Allocator const& a = {}) const
{
@@ -730,7 +730,7 @@ public:
allocator is used, and the return type of
the function becomes `std::string`.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -746,7 +746,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
password(
Allocator const& a = {}) const
{
@@ -882,7 +882,7 @@ public:
the default allocator is used, and the return
type of the function becomes `std::string`.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -900,7 +900,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
host(
Allocator const& a = {}) const
{
@@ -910,7 +910,7 @@ public:
urls::host_type::name)
{
// no decoding
- return string_value(s0, a);
+ return const_string(s0, a);
}
pct_decode_opts opt;
opt.plus_to_space = false;
diff --git a/include/boost/url/const_string.hpp b/include/boost/url/const_string.hpp
new file mode 100644
index 00000000..89fe6afb
--- /dev/null
+++ b/include/boost/url/const_string.hpp
@@ -0,0 +1,164 @@
+//
+// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// Official repository: https://github.com/CPPAlliance/url
+//
+
+#ifndef BOOST_URL_CONST_STRING_HPP
+#define BOOST_URL_CONST_STRING_HPP
+
+#include
+#include
+#include
+#include
+
+namespace boost {
+namespace urls {
+
+/** A constant string with shared ownership
+
+ Objects of this type represent read-only
+ strings with ownership of the character
+ buffer.
+
+ They are reference counted to allow cheap copies.
+
+ The type is derived from `string_view`,
+ which provides compatibility with strings
+ in terms of comparisons and conversions.
+
+ However, care must be exercised; undefined
+ behavior results if the string_view
+ portion of the object is modified
+ directly, for example by calling
+ `remove_suffix` or `operator=`.
+
+ Slicing, however, is supported, as
+ copies of the `string_view` portion
+ of the object are valid and remain
+ valid for the lifetime of the original
+ object.
+*/
+class const_string : public string_view
+{
+ struct base;
+
+ base* p_ = nullptr;
+
+ template
+ base*
+ construct(
+ std::size_t n,
+ Allocator const& a,
+ char*& dest);
+
+public:
+#ifdef BOOST_URL_DOCS
+ using allocator = __see_below__;
+#else
+ class allocator;
+#endif
+
+ /** Destructor
+
+ Upon destruction, ownership of the shared string is released. If
+ there are no more owners, the resources for the string are released.
+
+ */
+ inline
+ ~const_string();
+
+ /** Constructor
+
+ Default-constructed strings are empty
+
+ */
+ const_string() = default;
+
+ /** Constructor
+
+ This function creates a const_string of the specified size at the
+ destination with the a custom allocator.
+
+ This function sets the destination pointer to the new string address,
+ where the user can fill its contents while the const_string still
+ owns the buffer.
+
+ The buffer is destroyed after the last const_string that refers to it
+ is destroyed.
+
+ @tparam Allocator Allocator type
+
+ @param n Number of chars in the string `dest`
+
+ @param a Allocator to create a string in `dest`
+
+ @param dest Destination
+
+ */
+ template
+ const_string(
+ std::size_t n,
+ Allocator const& a,
+ char*& dest);
+
+ /** Constructor
+
+ This function constructs a copy of a @ref const_string with the
+ specified allocator.
+
+ This function allocates a @ref const_string the specified allocator
+ and copies its contents to this new string.
+
+ @tparam Allocator Allocator type
+
+ @param s The sting to copy
+
+ @param a allocator used to create this const_string
+
+ */
+ template< class Allocator =
+ std::allocator >
+ explicit
+ const_string(
+ string_view s,
+ Allocator const& a = {});
+
+ /** Copy constructor
+
+ This function constructs a copy of a const_string. As const_string
+ is read-only, this function can only copy and increment the string
+ reference counter.
+
+ @param other The string to copy
+
+ */
+ inline
+ const_string(
+ const_string const& other) noexcept;
+
+ /** Copy assignment
+
+ This function copy assigns a @ref const_string.
+
+ Objects of this type are cheap to copy.
+
+ @param other The string to copy
+
+ */
+ inline
+ const_string&
+ operator=(const_string const& other) & noexcept;
+};
+
+
+} // urls
+} // boost
+
+
+#include
+
+#endif
diff --git a/include/boost/url/impl/string.hpp b/include/boost/url/impl/const_string.hpp
similarity index 89%
rename from include/boost/url/impl/string.hpp
rename to include/boost/url/impl/const_string.hpp
index 73efdf05..ea4155f9 100644
--- a/include/boost/url/impl/string.hpp
+++ b/include/boost/url/impl/const_string.hpp
@@ -11,19 +11,20 @@
#define BOOST_URL_IMPL_STRING_HPP
#include
+#include
namespace boost {
namespace urls {
-struct string_value::base
+struct const_string::base
{
- std::size_t refs = 1;
+ std::atomic refs{1};
virtual void destroy() noexcept = 0;
};
template
auto
-string_value::
+const_string::
construct(
std::size_t n,
Allocator const& a,
@@ -75,8 +76,8 @@ construct(
return p;
}
-string_value::
-~string_value()
+const_string::
+~const_string()
{
if( p_ &&
--p_->refs == 0)
@@ -84,8 +85,8 @@ string_value::
}
template
-string_value::
-string_value(
+const_string::
+const_string(
std::size_t n,
Allocator const& a,
char*& dest)
@@ -94,8 +95,8 @@ string_value(
}
template
-string_value::
-string_value(
+const_string::
+const_string(
string_view s,
Allocator const& a)
{
@@ -106,9 +107,9 @@ string_value(
s.data(), s.size());
}
-string_value::
-string_value(
- string_value const& other) noexcept
+const_string::
+const_string(
+ const_string const& other) noexcept
: string_view(other)
, p_(other.p_)
{
@@ -116,10 +117,10 @@ string_value(
++p_->refs;
}
-string_value&
-string_value::
+const_string&
+const_string::
operator=(
- string_value const& other) & noexcept
+ const_string const& other) & noexcept
{
if( p_ &&
--p_->refs == 0)
@@ -134,7 +135,7 @@ operator=(
//------------------------------------------------
-class string_value::allocator
+class const_string::allocator
{
struct base
{
@@ -146,7 +147,7 @@ class string_value::allocator
}
virtual
- string_value
+ const_string
alloc(
std::size_t n,
char*& dest) = 0;
@@ -214,12 +215,12 @@ public:
{
}
- string_value
+ const_string
alloc(
std::size_t n,
char*& dest) override
{
- return string_value(
+ return const_string(
n, a_, dest);
}
@@ -235,8 +236,8 @@ public:
p_ = ::new(al.allocate(1)) impl(al);
}
- string_value
- make_string_value(
+ const_string
+ make_const_string(
std::size_t n,
char*& dest) const
{
diff --git a/include/boost/url/impl/params.hpp b/include/boost/url/impl/params.hpp
index e731207a..e6dda15d 100644
--- a/include/boost/url/impl/params.hpp
+++ b/include/boost/url/impl/params.hpp
@@ -22,14 +22,14 @@ class params::iterator
{
url const* u_ = nullptr;
std::size_t i_ = 0;
- string_value::allocator a_;
+ const_string::allocator a_;
friend class params;
iterator(
url const& u,
std::size_t i,
- string_value::allocator a) noexcept
+ const_string::allocator a) noexcept
: u_(&u)
, i_(i)
, a_(a)
diff --git a/include/boost/url/impl/params.ipp b/include/boost/url/impl/params.ipp
index c5da68d7..523443d9 100644
--- a/include/boost/url/impl/params.ipp
+++ b/include/boost/url/impl/params.ipp
@@ -24,7 +24,7 @@ reference(
char const* const s,
std::size_t const nk,
std::size_t const nv,
- string_value::allocator a)
+ const_string::allocator a)
{
if(nv > 0)
{
@@ -35,7 +35,7 @@ reference(
s + nk + 1, nv - 1 };
auto n = pct_decode_bytes_unchecked(ev);
char *dest;
- value = a.make_string_value(
+ value = a.make_const_string(
n, dest);
pct_decode_unchecked(
dest, dest + n, ev);
@@ -52,7 +52,7 @@ reference(
auto n =
pct_decode_bytes_unchecked(ek);
char* dest;
- key = a.make_string_value(n, dest);
+ key = a.make_const_string(n, dest);
pct_decode_unchecked(
dest, dest + nk, ek);
}
@@ -100,7 +100,7 @@ operator*() const ->
auto
params::
at(string_view key) const ->
- string_value
+ const_string
{
url::raw_param r;
auto it = find(key);
@@ -122,7 +122,7 @@ at(string_view key) const ->
auto n =
pct_decode_bytes_unchecked(ev);
char *dest;
- auto s = a_.make_string_value(n, dest);
+ auto s = a_.make_const_string(n, dest);
pct_decode_unchecked(
dest, dest + n, ev);
return s;
diff --git a/include/boost/url/impl/params_view.hpp b/include/boost/url/impl/params_view.hpp
index 44ae38af..fb4ca19b 100644
--- a/include/boost/url/impl/params_view.hpp
+++ b/include/boost/url/impl/params_view.hpp
@@ -24,7 +24,7 @@ class params_view::iterator
char const* p_ = nullptr;
std::size_t nk_ = 0;
std::size_t nv_ = 0;
- string_value::allocator a_;
+ const_string::allocator a_;
bool first_ = true;
friend class params_view;
@@ -33,13 +33,13 @@ class params_view::iterator
iterator(
string_view s,
- string_value::allocator a) noexcept;
+ const_string::allocator a) noexcept;
// end
iterator(
string_view s,
int,
- string_value::allocator a) noexcept;
+ const_string::allocator a) noexcept;
string_view
encoded_key() const noexcept;
diff --git a/include/boost/url/impl/params_view.ipp b/include/boost/url/impl/params_view.ipp
index 570fcb8e..b7ccaa9c 100644
--- a/include/boost/url/impl/params_view.ipp
+++ b/include/boost/url/impl/params_view.ipp
@@ -44,7 +44,7 @@ value_type(
char const* s,
std::size_t nk,
std::size_t const nv,
- string_value::allocator a)
+ const_string::allocator a)
{
if(nk + nv == 0)
{
@@ -61,7 +61,7 @@ value_type(
auto n =
pct_decode_bytes_unchecked(ev);
char *dest;
- value = a.make_string_value(
+ value = a.make_const_string(
n, dest);
pct_decode_unchecked(
dest, dest + n, ev);
@@ -75,7 +75,7 @@ value_type(
auto n =
pct_decode_bytes_unchecked(ek);
char* dest;
- key = a.make_string_value(n, dest);
+ key = a.make_const_string(n, dest);
pct_decode_unchecked(
dest, dest + nk, ek);
}
@@ -119,7 +119,7 @@ params_view::
iterator::
iterator(
string_view s,
- string_value::allocator a) noexcept
+ const_string::allocator a) noexcept
: end_(s.data() + s.size())
, p_(s.data())
, a_(a)
@@ -132,7 +132,7 @@ iterator::
iterator(
string_view s,
int,
- string_value::allocator a) noexcept
+ const_string::allocator a) noexcept
: end_(s.data() + s.size())
, p_(nullptr)
, a_(a)
@@ -208,8 +208,7 @@ operator==(
auto
params_view::
at(string_view key) const ->
- string_value
-{
+ const_string {
auto it = find(key);
for(;;)
{
@@ -227,7 +226,7 @@ at(string_view key) const ->
auto n =
pct_decode_bytes_unchecked(ev);
char *dest;
- auto s = a_.make_string_value(n, dest);
+ auto s = a_.make_const_string(n, dest);
pct_decode_unchecked(
dest, dest + n, ev);
return s;
diff --git a/include/boost/url/impl/pct_encoding.hpp b/include/boost/url/impl/pct_encoding.hpp
index 2519cd16..e193c4ea 100644
--- a/include/boost/url/impl/pct_encoding.hpp
+++ b/include/boost/url/impl/pct_encoding.hpp
@@ -193,7 +193,7 @@ pct_decode(
template<
class CharSet,
class Allocator>
-string_value
+const_string
pct_decode_to_value(
string_view s,
pct_decode_opts const& opt,
@@ -205,7 +205,7 @@ pct_decode_to_value(
grammar::is_charset::value);
if(s.empty())
- return string_value();
+ return const_string();
error_code ec;
auto const n =
validate_pct_encoding(
@@ -214,7 +214,7 @@ pct_decode_to_value(
detail::throw_invalid_argument(
BOOST_CURRENT_LOCATION);
char* dest;
- string_value r(n, a, dest);
+ const_string r(n, a, dest);
pct_decode_unchecked(
dest, dest + n, s, opt);
return r;
@@ -223,7 +223,7 @@ pct_decode_to_value(
//------------------------------------------------
template
-string_value
+const_string
pct_decode_unchecked(
string_view s,
pct_decode_opts const& opt,
@@ -234,7 +234,7 @@ pct_decode_unchecked(
decoded_size =
pct_decode_bytes_unchecked(s);
char* dest;
- string_value r(
+ const_string r(
decoded_size, a, dest);
pct_decode_unchecked(
dest, dest + decoded_size,
@@ -408,7 +408,7 @@ pct_encode(
template<
class CharSet,
class Allocator>
-string_value
+const_string
pct_encode_to_value(
string_view s,
pct_encode_opts const& opt,
@@ -420,11 +420,11 @@ pct_encode_to_value(
grammar::is_charset::value);
if(s.empty())
- return string_value();
+ return const_string();
auto const n =
pct_encode_bytes(s, opt, cs);
char* dest;
- string_value r(n, a, dest);
+ const_string r(n, a, dest);
char const* end = dest + n;
auto const n1 = pct_encode(
dest, end, s, opt, cs);
diff --git a/include/boost/url/impl/segments.hpp b/include/boost/url/impl/segments.hpp
index 7babe538..5883b38d 100644
--- a/include/boost/url/impl/segments.hpp
+++ b/include/boost/url/impl/segments.hpp
@@ -31,14 +31,14 @@ class segments::iterator
{
url const* u_ = nullptr;
std::size_t i_ = 0;
- string_value::allocator a_;
+ const_string::allocator a_;
friend class segments;
iterator(
url const& u,
std::size_t i,
- string_value::allocator
+ const_string::allocator
const& a) noexcept
: u_(&u)
, i_(i)
@@ -47,8 +47,8 @@ class segments::iterator
}
public:
- using value_type = string_value;
- using reference = string_value;
+ using value_type = const_string;
+ using reference = const_string;
using pointer = void const*;
using difference_type = std::ptrdiff_t;
using iterator_category =
@@ -87,7 +87,7 @@ public:
}
BOOST_URL_DECL
- string_value
+ const_string
operator*() const;
friend
@@ -166,7 +166,7 @@ public:
std::ptrdiff_t>(a.i_) - b.i_;
}
- string_value
+ const_string
operator[](ptrdiff_t n) const
{
return *(*this + n);
@@ -272,7 +272,7 @@ assign(FwdIt first, FwdIt last) ->
auto
segments::
at(std::size_t i) const ->
- string_value
+ const_string
{
if(i >= size())
detail::throw_out_of_range(
@@ -283,7 +283,7 @@ at(std::size_t i) const ->
auto
segments::
front() const ->
- string_value
+ const_string
{
BOOST_ASSERT(! empty());
return (*this)[0];
@@ -292,7 +292,7 @@ front() const ->
auto
segments::
back() const ->
- string_value
+ const_string
{
BOOST_ASSERT(! empty());
return (*this)[size() - 1];
diff --git a/include/boost/url/impl/segments.ipp b/include/boost/url/impl/segments.ipp
index 02968633..9286e839 100644
--- a/include/boost/url/impl/segments.ipp
+++ b/include/boost/url/impl/segments.ipp
@@ -21,7 +21,7 @@ namespace urls {
//------------------------------------------------
-string_value
+const_string
segments::
iterator::
operator*() const
@@ -41,7 +41,7 @@ operator*() const
pct_decode_bytes_unchecked(s);
char* dest;
auto v =
- a_.make_string_value(n, dest);
+ a_.make_const_string(n, dest);
pct_decode_opts opt;
opt.plus_to_space = false;
pct_decode_unchecked(
@@ -59,7 +59,7 @@ auto
segments::
operator[](
std::size_t i) const ->
- string_value
+ const_string
{
BOOST_ASSERT(i < u_->nseg_);
auto p0 = u_->segment(i);
@@ -76,7 +76,7 @@ operator[](
pct_decode_bytes_unchecked(s);
char* dest;
auto v =
- a_.make_string_value(n, dest);
+ a_.make_const_string(n, dest);
pct_decode_opts opt;
opt.plus_to_space = false;
pct_decode_unchecked(
diff --git a/include/boost/url/impl/segments_view.hpp b/include/boost/url/impl/segments_view.hpp
index ccb7b5c8..f11f4447 100644
--- a/include/boost/url/impl/segments_view.hpp
+++ b/include/boost/url/impl/segments_view.hpp
@@ -24,7 +24,7 @@ class segments_view::
char const* pos_ = nullptr;
char const* next_ = nullptr;
char const* end_ = nullptr;
- string_value::allocator a_;
+ const_string::allocator a_;
pct_encoded_str t_;
friend segments_view;
@@ -33,7 +33,7 @@ class segments_view::
iterator(
string_view s,
std::size_t nseg,
- string_value::
+ const_string::
allocator const& a) noexcept;
// end ctor
@@ -41,13 +41,13 @@ class segments_view::
iterator(
string_view s,
std::size_t nseg,
- string_value::
+ const_string::
allocator const& a,
int) noexcept;
public:
- using value_type = string_value;
- using reference = string_value;
+ using value_type = const_string;
+ using reference = const_string;
using pointer = void const*;
using difference_type = std::ptrdiff_t;
using iterator_category =
@@ -66,7 +66,7 @@ public:
iterator const&) noexcept;
BOOST_URL_DECL
- string_value
+ const_string
operator*() const noexcept;
bool
@@ -146,7 +146,7 @@ is_absolute() const noexcept
//
//------------------------------------------------
-string_value
+const_string
segments_view::
front() const noexcept
{
@@ -154,7 +154,7 @@ front() const noexcept
return *begin();
}
-string_value
+const_string
segments_view::
back() const noexcept
{
diff --git a/include/boost/url/impl/segments_view.ipp b/include/boost/url/impl/segments_view.ipp
index 1a52f8e0..17d27eaa 100644
--- a/include/boost/url/impl/segments_view.ipp
+++ b/include/boost/url/impl/segments_view.ipp
@@ -25,7 +25,7 @@ iterator::
iterator(
string_view s,
std::size_t nseg,
- string_value::allocator const& a) noexcept
+ const_string::allocator const& a) noexcept
: begin_(s.data())
, pos_(s.data())
, next_(s.data())
@@ -54,7 +54,7 @@ iterator::
iterator(
string_view s,
std::size_t nseg,
- string_value::
+ const_string::
allocator const& a,
int) noexcept
: i_(nseg)
@@ -84,13 +84,13 @@ operator=(
iterator const&) noexcept ->
iterator& = default;
-string_value
+const_string
segments_view::
iterator::
operator*() const noexcept
{
char* dest;
- auto s = a_.make_string_value(
+ auto s = a_.make_const_string(
t_.decoded_size, dest);
pct_decode_opts opt;
opt.plus_to_space = false;
diff --git a/include/boost/url/ipv4_address.hpp b/include/boost/url/ipv4_address.hpp
index 73569e65..1bb755ce 100644
--- a/include/boost/url/ipv4_address.hpp
+++ b/include/boost/url/ipv4_address.hpp
@@ -12,7 +12,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -160,18 +160,18 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
*/
template>
- string_value
+ const_string
to_string(Allocator const& a = {}) const
{
char buf[max_str_len];
auto const n = print_impl(buf);
char* dest;
- string_value s(n, a, dest);
+ const_string s(n, a, dest);
std::memcpy(dest, buf, n);
return s;
}
diff --git a/include/boost/url/ipv6_address.hpp b/include/boost/url/ipv6_address.hpp
index b04fcf18..e769c16b 100644
--- a/include/boost/url/ipv6_address.hpp
+++ b/include/boost/url/ipv6_address.hpp
@@ -12,7 +12,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -185,7 +185,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -194,13 +194,13 @@ public:
*/
template>
- string_value
+ const_string
to_string(Allocator const& a = {}) const
{
char buf[max_str_len];
auto const n = print_impl(buf);
char* dest;
- string_value s(n, a, dest);
+ const_string s(n, a, dest);
std::memcpy(dest, buf, n);
return s;
}
diff --git a/include/boost/url/params.hpp b/include/boost/url/params.hpp
index 4a94b3ed..85d0d16b 100644
--- a/include/boost/url/params.hpp
+++ b/include/boost/url/params.hpp
@@ -12,7 +12,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -48,7 +48,7 @@ class params
This is the allocator used to create read-only strings
when iterators are dereferenced.
*/
- string_value::allocator a_;
+ const_string::allocator a_;
/** Construct query params from a url
@@ -110,7 +110,7 @@ public:
char const* s,
std::size_t nk,
std::size_t nv,
- string_value::allocator a);
+ const_string::allocator a);
public:
/** The query key.
@@ -119,7 +119,7 @@ public:
holds the query key with percent-decoding
applied.
*/
- string_value key;
+ const_string key;
/** The query value.
@@ -128,7 +128,7 @@ public:
applied. The field @ref has_value indicates
if the query value is defined.
*/
- string_value value;
+ const_string value;
/** True if the query parameter has a value.
@@ -270,7 +270,7 @@ public:
*/
BOOST_URL_DECL
- string_value
+ const_string
at(string_view key) const;
/** Access element at specified position without bounds checking
diff --git a/include/boost/url/params_encoded_view.hpp b/include/boost/url/params_encoded_view.hpp
index 8e99f6b6..3fc94021 100644
--- a/include/boost/url/params_encoded_view.hpp
+++ b/include/boost/url/params_encoded_view.hpp
@@ -119,7 +119,7 @@ public:
This function returns a new view over the
same underlying character buffer where each
- segment is returned as a @ref string_value
+ segment is returned as a @ref const_string
with percent-decoding applied using the
optionally specified allocator.
diff --git a/include/boost/url/params_view.hpp b/include/boost/url/params_view.hpp
index 63e09f75..138a5156 100644
--- a/include/boost/url/params_view.hpp
+++ b/include/boost/url/params_view.hpp
@@ -11,7 +11,7 @@
#define BOOST_URL_PARAMS_VIEW_HPP
#include
-#include
+#include
#include
#include
#include
@@ -32,7 +32,7 @@ class params_view
string_view s_;
std::size_t n_;
- string_value::allocator a_;
+ const_string::allocator a_;
template
params_view(
@@ -58,8 +58,8 @@ public:
class value_type
{
public:
- string_value key;
- string_value value;
+ const_string key;
+ const_string value;
bool has_value;
BOOST_URL_DECL
@@ -86,7 +86,7 @@ public:
char const* s,
std::size_t nk,
std::size_t nv,
- string_value::allocator a);
+ const_string::allocator a);
};
using reference = value_type;
@@ -101,7 +101,7 @@ public:
//--------------------------------------------
BOOST_URL_DECL
- string_value
+ const_string
at(string_view key) const;
//--------------------------------------------
diff --git a/include/boost/url/pct_encoding.hpp b/include/boost/url/pct_encoding.hpp
index a7037b4c..6cf56cfb 100644
--- a/include/boost/url/pct_encoding.hpp
+++ b/include/boost/url/pct_encoding.hpp
@@ -12,7 +12,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -227,7 +227,7 @@ pct_decode(
the given percent-encoded string, by
converting escape sequences into their
character equivalent.
- The result is returned as a @ref string_value
+ The result is returned as a @ref const_string
the optionally specified allocator.
@par Exception Safety
@@ -270,7 +270,7 @@ pct_decode(
template<
class CharSet = reserved_chars_t,
class Allocator = std::allocator >
-string_value
+const_string
pct_decode_to_value(
string_view s,
pct_decode_opts const& opt = {},
@@ -377,7 +377,7 @@ pct_decode_unchecked(
*/
template >
-string_value
+const_string
pct_decode_unchecked(
string_view s,
pct_decode_opts const& opt = {},
@@ -580,7 +580,7 @@ pct_encode(
the given plain string, by escaping all
characters that are not in the specified
CharSet.
- The result is returned as a @ref string_value
+ The result is returned as a @ref const_string
using the optionally specified allocator.
@par Example
@@ -588,7 +588,7 @@ pct_encode(
pct_encode_opts opt;
opt.space_to_plus = true;
- string_value s = pct_encode_to_value( "My Stuff", pchars, opt );
+ const_string s = pct_encode_to_value( "My Stuff", pchars, opt );
assert( s == "My+Stuff" );
@endcode
@@ -596,7 +596,7 @@ pct_encode(
@par Exception Safety
Calls to allocate may throw.
- @return A @ref string_value holding the
+ @return A @ref const_string holding the
encoded string.
@param s The string to encode.
@@ -623,7 +623,7 @@ pct_encode(
template<
class CharSet = reserved_chars_t,
class Allocator = std::allocator >
-string_value
+const_string
pct_encode_to_value(
string_view s,
pct_encode_opts const& opt = {},
diff --git a/include/boost/url/segments.hpp b/include/boost/url/segments.hpp
index 6cfe6905..bfa73832 100644
--- a/include/boost/url/segments.hpp
+++ b/include/boost/url/segments.hpp
@@ -11,7 +11,7 @@
#define BOOST_URL_SEGMENTS_HPP
#include
-#include
+#include
#include
#include
#include
@@ -67,7 +67,7 @@ class segments
: private detail::parts_base
{
url* u_ = nullptr;
- string_value::allocator a_;
+ const_string::allocator a_;
friend class url;
@@ -97,11 +97,11 @@ public:
a segment where ownership is retained
in the copy.
*/
- using value_type = string_value;
+ using value_type = const_string;
- using reference = string_value;
+ using reference = const_string;
- using const_reference = string_value;
+ using const_reference = const_string;
/** An unsigned integer type
*/
@@ -234,7 +234,7 @@ public:
element.
*/
inline
- string_value
+ const_string
at(std::size_t i) const;
/** Return an element
@@ -256,20 +256,20 @@ public:
element.
*/
BOOST_URL_DECL
- string_value
+ const_string
operator[](
std::size_t i) const;
/** Return the first element
*/
inline
- string_value
+ const_string
front() const;
/** Return the last element
*/
inline
- string_value
+ const_string
back() const;
//--------------------------------------------
diff --git a/include/boost/url/segments_encoded_view.hpp b/include/boost/url/segments_encoded_view.hpp
index 1e2d4cf4..812df5f5 100644
--- a/include/boost/url/segments_encoded_view.hpp
+++ b/include/boost/url/segments_encoded_view.hpp
@@ -144,7 +144,7 @@ public:
This function returns a new view over the
same underlying character buffer where each
- segment is returned as a @ref string_value
+ segment is returned as a @ref const_string
with percent-decoding applied using the
optionally specified allocator.
diff --git a/include/boost/url/segments_view.hpp b/include/boost/url/segments_view.hpp
index 7b27eeb6..6d833eb1 100644
--- a/include/boost/url/segments_view.hpp
+++ b/include/boost/url/segments_view.hpp
@@ -11,7 +11,7 @@
#define BOOST_URL_SEGMENTS_VIEW_HPP
#include
-#include
+#include
#include
#include
@@ -32,7 +32,7 @@ class segments_view
{
string_view s_;
std::size_t n_ = 0;
- string_value::allocator a_;
+ const_string::allocator a_;
friend class url_view;
friend class segments_encoded_view;
@@ -54,15 +54,15 @@ public:
/** The type of value returned when dereferencing an iterator.
*/
- using value_type = string_value;
+ using value_type = const_string;
/** The type of value returned when dereferencing an iterator.
*/
- using reference = string_value;
+ using reference = const_string;
/** The type of value returned when dereferencing an iterator.
*/
- using const_reference = string_value;
+ using const_reference = const_string;
/** The unsigned integer type used to represent size.
*/
@@ -104,13 +104,13 @@ public:
/** Return the first element.
*/
inline
- string_value
+ const_string
front() const noexcept;
/** Return the last element.
*/
inline
- string_value
+ const_string
back() const noexcept;
//--------------------------------------------
diff --git a/include/boost/url/string.hpp b/include/boost/url/string.hpp
deleted file mode 100644
index ab6545a0..00000000
--- a/include/boost/url/string.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-//
-// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-// Official repository: https://github.com/CPPAlliance/url
-//
-
-#ifndef BOOST_URL_STRING_HPP
-#define BOOST_URL_STRING_HPP
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace boost {
-namespace urls {
-
-/** A read-only, reference counted string
-
- Objects of this type represent read-only
- strings with ownership of the character
- buffer. They are reference counted which
- makes copies cheap. The type is derived
- from @ref string_view which provides
- compatibility with strings in terms of
- comparisons and converisons. However,
- care must be exercised; undefined
- behavior results if the string_view
- portion of the object is modified
- directly, for example by calling
- `remove_suffix` or `operator=`.
-
- Slicing however, is supported, as
- copies of the `string_view` portion
- of the object are valid and remain
- valid for the lifetime of the oriignal
- object.
-*/
-class string_value : public string_view
-{
- struct base;
-
- base* p_ = nullptr;
-
- template
- base*
- construct(
- std::size_t n,
- Allocator const& a,
- char*& dest);
-
-public:
- class allocator;
-
- inline
- ~string_value();
-
- string_value() = default;
-
- template
- string_value(
- std::size_t n,
- Allocator const& a,
- char*& dest);
-
- template< class Allocator =
- std::allocator >
- explicit
- string_value(
- string_view s,
- Allocator const& a = {});
-
- inline
- string_value(
- string_value const& other) noexcept;
-
- inline
- string_value&
- operator=(string_value const& other) & noexcept;
-};
-
-} // urls
-} // boost
-
-#include
-
-#endif
diff --git a/include/boost/url/url_view.hpp b/include/boost/url/url_view.hpp
index b9e94be8..ddeb5a61 100644
--- a/include/boost/url/url_view.hpp
+++ b/include/boost/url/url_view.hpp
@@ -719,7 +719,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -733,7 +733,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
userinfo(
Allocator const& a = {}) const
{
@@ -809,7 +809,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -825,7 +825,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
user(
Allocator const& a = {}) const
{
@@ -925,7 +925,7 @@ public:
allocator is used, and the return type of
the function becomes `std::string`.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -941,7 +941,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
password(
Allocator const& a = {}) const
{
@@ -1077,7 +1077,7 @@ public:
the default allocator is used, and the return
type of the function becomes `std::string`.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -1095,7 +1095,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
host(
Allocator const& a = {}) const
{
@@ -1105,7 +1105,7 @@ public:
urls::host_type::name)
{
// no decoding
- return string_value(s0, a);
+ return const_string(s0, a);
}
pct_decode_opts opt;
opt.plus_to_space = false;
@@ -1527,7 +1527,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@par Specification
@@ -1541,7 +1541,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
query(
Allocator const& a = {}) const
{
@@ -1683,7 +1683,7 @@ public:
string will use. If this parameter is omitted,
the default allocator is used.
- @return A @ref string_value using the
+ @return A @ref const_string using the
specified allocator.
@see
@@ -1693,7 +1693,7 @@ public:
template<
class Allocator =
std::allocator>
- string_value
+ const_string
fragment(
Allocator const& a = {}) const
{
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 2f6ea382..5a7ce1ae 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -38,7 +38,7 @@ set(BOOST_URL_TESTS_FILES
segments_view.cpp
static_pool.cpp
static_url.cpp
- string.cpp
+ const_string.cpp
string_view.cpp
url.cpp
url_view.cpp
diff --git a/test/unit/Jamfile b/test/unit/Jamfile
index d1c38392..9a973e43 100644
--- a/test/unit/Jamfile
+++ b/test/unit/Jamfile
@@ -42,7 +42,7 @@ local SOURCES =
segments_view.cpp
static_pool.cpp
static_url.cpp
- string.cpp
+ const_string.cpp
string_view.cpp
url.cpp
url_view.cpp
diff --git a/test/unit/string.cpp b/test/unit/const_string.cpp
similarity index 91%
rename from test/unit/string.cpp
rename to test/unit/const_string.cpp
index c6793b48..47021d7b 100644
--- a/test/unit/string.cpp
+++ b/test/unit/const_string.cpp
@@ -8,7 +8,7 @@
//
// Test that header file is self-contained.
-#include
+#include
#include "test_suite.hpp"
@@ -26,7 +26,7 @@ public:
void
run()
{
- string_value sv("hello");
+ const_string sv("hello");
auto sv2 = sv;
BOOST_TEST(sv2 == sv);
sv = {};
diff --git a/test/unit/pct_encoding.cpp b/test/unit/pct_encoding.cpp
index e8cd46ff..fe18faa4 100644
--- a/test/unit/pct_encoding.cpp
+++ b/test/unit/pct_encoding.cpp
@@ -118,7 +118,7 @@ public:
}
// pct_decode_to_value()
{
- string_value s =
+ const_string s =
pct_decode_to_value(
s0, opt, *pcs);
BOOST_TEST(s == s1);
@@ -126,7 +126,7 @@ public:
// pct_decode_to_value(Allocator)
{
static_pool<256> p;
- string_value s =
+ const_string s =
pct_decode_to_value(
s0, opt, *pcs,
p.allocator());
diff --git a/test/unit/segments_view.cpp b/test/unit/segments_view.cpp
index dbb2ea9a..e6ec517f 100644
--- a/test/unit/segments_view.cpp
+++ b/test/unit/segments_view.cpp
@@ -88,7 +88,7 @@ public:
sv = f(s).value().decoded(sp.allocator()));
// forward
{
- std::vector v1;
+ std::vector v1;
std::copy(
sv.begin(),
sv.end(),
@@ -97,7 +97,7 @@ public:
}
// reverse
{
- std::vector v1;
+ std::vector v1;
std::copy(
reverse(sv.end()),
reverse(sv.begin()),
diff --git a/test/unit/static_pool.cpp b/test/unit/static_pool.cpp
index 79d79c3a..7580de6e 100644
--- a/test/unit/static_pool.cpp
+++ b/test/unit/static_pool.cpp
@@ -10,7 +10,7 @@
// Test that header file is self-contained.
#include
-#include
+#include
#include "test_suite.hpp"
#include
@@ -24,13 +24,13 @@ public:
template>
static
- string_value
+ const_string
make_string(
string_view s,
Allocator const& a = {})
{
char* dest;
- string_value sv(
+ const_string sv(
s.size(), a, dest);
std::memcpy(dest,
s.data(), s.size());