123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- #ifndef BOOST_URL_PCT_STRING_VIEW_HPP
- #define BOOST_URL_PCT_STRING_VIEW_HPP
- #include <boost/url/detail/config.hpp>
- #include <boost/url/encoding_opts.hpp>
- #include <boost/url/error_types.hpp>
- #include <boost/core/detail/string_view.hpp>
- #include <boost/url/grammar/string_token.hpp>
- #include <boost/url/grammar/string_view_base.hpp>
- #include <cstddef>
- #include <iterator>
- #include <string>
- #include <type_traits>
- #include <utility>
- namespace boost {
- namespace urls {
- #ifndef BOOST_URL_DOCS
- class decode_view;
- class pct_string_view;
- pct_string_view
- make_pct_string_view_unsafe(
- char const*, std::size_t,
- std::size_t) noexcept;
- namespace detail {
- core::string_view&
- ref(pct_string_view& s) noexcept;
- }
- #endif
- class pct_string_view final
- : public grammar::string_view_base
- {
- std::size_t dn_ = 0;
- #ifndef BOOST_URL_DOCS
- friend
- pct_string_view
- make_pct_string_view_unsafe(
- char const*, std::size_t,
- std::size_t) noexcept;
- friend
- core::string_view&
- detail::ref(pct_string_view&) noexcept;
- #endif
-
- pct_string_view(
- char const* data,
- std::size_t size,
- std::size_t dn) noexcept
- : string_view_base(data, size)
- , dn_(dn)
- {
- }
- BOOST_URL_DECL
- void
- decode_impl(
- string_token::arg& dest,
- encoding_opts opt) const;
- public:
-
- constexpr pct_string_view() = default;
-
- constexpr
- pct_string_view(
- pct_string_view const& other) = default;
-
- template<
- class String
- #ifndef BOOST_URL_DOCS
- , class = typename std::enable_if<
- std::is_convertible<
- String,
- core::string_view
- >::value>::type
- #endif
- >
- pct_string_view(
- String const& s)
- : pct_string_view(
- detail::to_sv(s))
- {
- }
-
- pct_string_view(
- std::nullptr_t) = delete;
-
- pct_string_view(
- char const* s,
- std::size_t len)
- : pct_string_view(
- core::string_view(s, len))
- {
- }
-
- BOOST_URL_DECL
- pct_string_view(
- core::string_view s);
-
- pct_string_view& operator=(
- pct_string_view const& other) = default;
- friend
- BOOST_URL_DECL
- system::result<pct_string_view>
- make_pct_string_view(
- core::string_view s) noexcept;
-
-
- std::size_t
- decoded_size() const noexcept
- {
- return dn_;
- }
-
- decode_view
- operator*() const noexcept;
-
- template<BOOST_URL_STRTOK_TPARAM>
- BOOST_URL_STRTOK_RETURN
- decode(
- encoding_opts opt = {},
- BOOST_URL_STRTOK_ARG(token)) const
- {
- static_assert(
- string_token::is_token<
- StringToken>::value,
- "Type requirements not met");
- decode_impl(token, opt);
- return token.result();
- }
- #ifndef BOOST_URL_DOCS
-
- pct_string_view const*
- operator->() const noexcept
- {
- return this;
- }
- #endif
-
-
-
- void swap(
- pct_string_view& s ) noexcept
- {
- string_view_base::swap(s);
- std::swap(dn_, s.dn_);
- }
- };
- #ifndef BOOST_URL_DOCS
- namespace detail {
- inline
- core::string_view&
- ref(pct_string_view& s) noexcept
- {
- return s.s_;
- }
- }
- #endif
- BOOST_URL_DECL
- system::result<pct_string_view>
- make_pct_string_view(
- core::string_view s) noexcept;
- #ifndef BOOST_URL_DOCS
- inline
- pct_string_view
- make_pct_string_view_unsafe(
- char const* data,
- std::size_t size,
- std::size_t decoded_size) noexcept
- {
- #if 0
- BOOST_ASSERT(! make_pct_string_view(
- core::string_view(data, size)).has_error());
- #endif
- return pct_string_view(
- data, size, decoded_size);
- }
- #endif
- #ifndef BOOST_URL_DOCS
- namespace detail {
- template <>
- inline
- core::string_view
- to_sv(pct_string_view const& s) noexcept
- {
- return s.substr();
- }
- }
- #endif
- }
- }
- #endif
|