Files
boost_beast/include/boost/beast/http/impl/rfc7230.hpp
T

424 lines
6.8 KiB
C++
Raw Normal View History

2016-05-24 06:17:04 -04:00
//
2019-02-21 07:00:31 -08:00
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2016-05-24 06:17:04 -04:00
//
// 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)
//
2017-07-20 13:40:34 -07:00
// Official repository: https://github.com/boostorg/beast
//
2016-05-24 06:17:04 -04:00
2019-02-22 13:06:43 -08:00
#ifndef BOOST_BEAST_HTTP_IMPL_RFC7230_HPP
#define BOOST_BEAST_HTTP_IMPL_RFC7230_HPP
2016-05-24 06:17:04 -04:00
2017-07-20 13:40:34 -07:00
#include <boost/beast/http/detail/rfc7230.hpp>
2016-05-24 06:17:04 -04:00
#include <iterator>
2017-07-20 13:40:34 -07:00
namespace boost {
2016-05-24 06:17:04 -04:00
namespace beast {
namespace http {
class param_list::const_iterator
{
2017-05-05 14:45:15 -07:00
using iter_type = string_view::const_iterator;
2016-05-24 06:17:04 -04:00
std::string s_;
detail::param_iter pi_;
public:
using value_type = param_list::value_type;
using pointer = value_type const*;
using reference = value_type const&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;
const_iterator() = default;
bool
operator==(const_iterator const& other) const
{
return
other.pi_.it == pi_.it &&
2016-06-05 13:39:13 -04:00
other.pi_.last == pi_.last &&
other.pi_.first == pi_.first;
2016-05-24 06:17:04 -04:00
}
bool
operator!=(const_iterator const& other) const
{
return !(*this == other);
}
reference
operator*() const
{
return pi_.v;
}
pointer
operator->() const
{
return &*(*this);
}
const_iterator&
operator++()
{
increment();
return *this;
}
const_iterator
operator++(int)
{
auto temp = *this;
++(*this);
return temp;
}
private:
friend class param_list;
2016-06-05 13:39:13 -04:00
const_iterator(iter_type first, iter_type last)
2016-05-24 06:17:04 -04:00
{
2016-06-05 13:39:13 -04:00
pi_.it = first;
pi_.first = first;
pi_.last = last;
2016-05-24 06:17:04 -04:00
increment();
}
BOOST_BEAST_DECL
2016-05-24 06:17:04 -04:00
static
std::string
2017-06-04 10:52:28 -07:00
unquote(string_view sr);
2016-05-24 06:17:04 -04:00
BOOST_BEAST_DECL
2016-05-24 06:17:04 -04:00
void
increment();
};
inline
auto
param_list::
begin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
param_list::
end() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
inline
auto
param_list::
cbegin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
param_list::
cend() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
//------------------------------------------------------------------------------
class ext_list::const_iterator
{
ext_list::value_type v_;
iter_type it_;
2016-06-05 13:39:13 -04:00
iter_type first_;
iter_type last_;
2016-05-24 06:17:04 -04:00
public:
using value_type = ext_list::value_type;
using pointer = value_type const*;
using reference = value_type const&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
const_iterator() = default;
bool
operator==(const_iterator const& other) const
{
return
other.it_ == it_ &&
2016-06-05 13:39:13 -04:00
other.first_ == first_ &&
other.last_ == last_;
2016-05-24 06:17:04 -04:00
}
bool
operator!=(const_iterator const& other) const
{
return !(*this == other);
}
reference
operator*() const
{
return v_;
}
pointer
operator->() const
{
return &*(*this);
}
const_iterator&
operator++()
{
increment();
return *this;
}
const_iterator
operator++(int)
{
auto temp = *this;
++(*this);
return temp;
}
private:
friend class ext_list;
const_iterator(iter_type begin, iter_type end)
{
it_ = begin;
2016-06-05 13:39:13 -04:00
first_ = begin;
last_ = end;
2016-05-24 06:17:04 -04:00
increment();
}
BOOST_BEAST_DECL
2016-05-24 06:17:04 -04:00
void
increment();
};
inline
auto
ext_list::
begin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
ext_list::
end() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
inline
auto
ext_list::
cbegin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
ext_list::
cend() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
template<class T>
auto
ext_list::
find(T const& s) ->
const_iterator
{
return std::find_if(begin(), end(),
[&s](value_type const& v)
{
2017-06-16 09:38:53 -07:00
return iequals(s, v.first);
2016-05-24 06:17:04 -04:00
});
}
template<class T>
bool
ext_list::
exists(T const& s)
{
return find(s) != end();
}
//------------------------------------------------------------------------------
class token_list::const_iterator
{
token_list::value_type v_;
iter_type it_;
2016-06-05 13:39:13 -04:00
iter_type first_;
iter_type last_;
2016-05-24 06:17:04 -04:00
public:
using value_type = token_list::value_type;
using pointer = value_type const*;
using reference = value_type const&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
const_iterator() = default;
bool
operator==(const_iterator const& other) const
{
return
other.it_ == it_ &&
2016-06-05 13:39:13 -04:00
other.first_ == first_ &&
other.last_ == last_;
2016-05-24 06:17:04 -04:00
}
bool
operator!=(const_iterator const& other) const
{
return !(*this == other);
}
reference
operator*() const
{
return v_;
}
pointer
operator->() const
{
return &*(*this);
}
const_iterator&
operator++()
{
increment();
return *this;
}
const_iterator
operator++(int)
{
auto temp = *this;
++(*this);
return temp;
}
private:
friend class token_list;
const_iterator(iter_type begin, iter_type end)
{
it_ = begin;
2016-06-05 13:39:13 -04:00
first_ = begin;
last_ = end;
2016-05-24 06:17:04 -04:00
increment();
}
BOOST_BEAST_DECL
2016-05-24 06:17:04 -04:00
void
increment();
};
inline
auto
token_list::
begin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
token_list::
end() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
inline
auto
token_list::
cbegin() const ->
const_iterator
{
return const_iterator{s_.begin(), s_.end()};
}
inline
auto
token_list::
cend() const ->
const_iterator
{
return const_iterator{s_.end(), s_.end()};
}
template<class T>
bool
token_list::
exists(T const& s)
{
return std::find_if(begin(), end(),
[&s](value_type const& v)
{
2017-06-16 09:38:53 -07:00
return iequals(s, v);
2016-05-24 06:17:04 -04:00
}
) != end();
}
2016-11-20 07:32:41 -05:00
template<class Policy>
bool
validate_list(detail::basic_parsed_list<
Policy> const& list)
{
auto const last = list.end();
auto it = list.begin();
if(it.error())
return false;
while(it != last)
{
++it;
if(it.error())
return false;
if(it == last)
break;
}
return true;
}
2016-05-24 06:17:04 -04:00
} // http
} // beast
2017-07-20 13:40:34 -07:00
} // boost
2016-05-24 06:17:04 -04:00
#ifdef BOOST_BEAST_HEADER_ONLY
#include <boost/beast/http/impl/rfc7230.ipp>
#endif
2016-05-24 06:17:04 -04:00
#endif