Skip to content

Commit

Permalink
field parsing rules defined in private headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Feb 9, 2024
1 parent 02eb015 commit 00ebd90
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 32 deletions.
30 changes: 0 additions & 30 deletions include/boost/http_proto/rfc/detail/rules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,6 @@ status_line_rule =

//------------------------------------------------

// header-field = field-name ":" OWS field-value OWS
struct field_name_rule_t
{
using value_type = core::string_view;

system::result<value_type>
parse(
char const *&it,
char const *end) const noexcept;
};

constexpr field_name_rule_t field_name_rule{};

struct field_value_rule_t
{
struct value_type
{
core::string_view value;
bool has_obs_fold = false;
bool has_crlf = false;
};

system::result<value_type>
parse(
char const *&it,
char const *end) const noexcept;
};

constexpr field_value_rule_t field_value_rule{};

struct field_rule_t
{
struct value_type
Expand Down
3 changes: 3 additions & 0 deletions src/fields_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
#include <boost/assert.hpp>
#include <boost/assert/source_location.hpp>

#include <boost/system/result.hpp>

#include <boost/url/grammar/ci_string.hpp>
#include <boost/url/grammar/error.hpp>
#include <boost/url/grammar/parse.hpp>
#include <boost/url/grammar/token_rule.hpp>

#include "detail/move_chars.hpp"
#include "rfc/detail/rules.hpp"

namespace boost {
namespace http_proto {
Expand Down
4 changes: 2 additions & 2 deletions src/rfc/detail/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <boost/url/grammar/parse.hpp>
#include <boost/url/grammar/tuple_rule.hpp>

#include "rules.hpp"

namespace boost {
namespace http_proto {
namespace detail {
Expand Down Expand Up @@ -271,10 +273,8 @@ parse(
goto done;

if( end - it < 3 )
{
BOOST_HTTP_PROTO_RETURN_EC(
grammar::error::need_more);
}

if(! ws(it[2]) )
{
Expand Down
61 changes: 61 additions & 0 deletions src/rfc/detail/rules.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright (c) 2024 Christian Mazakas
//
// 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/http_proto
//

#ifndef BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP
#define BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP

#include <boost/core/detail/string_view.hpp>
#include <boost/system/result.hpp>

namespace boost
{
namespace http_proto
{
namespace detail
{

// header-field = field-name ":" OWS field-value OWS
struct field_name_rule_t
{
using value_type = core::string_view;

system::result<value_type>
parse(
char const*& it,
char const* end) const noexcept;
};

constexpr field_name_rule_t field_name_rule{};

struct field_value_rule_t
{
struct value_type
{
core::string_view value;
// detected occurrence of `\r\n `, `\r\n\t`
bool has_obs_fold = false;
// detected `\r\nX`, attempt at field termination
bool has_crlf = false;
};

system::result<value_type>
parse(
char const*& it,
char const* end) const noexcept;
};

constexpr field_value_rule_t field_value_rule{};

} // namespace detail
} // namespace http_proto
} // namespace boost



#endif // BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP

0 comments on commit 00ebd90

Please sign in to comment.