Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:27

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_GRAMMAR_DELIM_RULE_HPP
0011 #define BOOST_URL_GRAMMAR_DELIM_RULE_HPP
0012 
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/core/detail/string_view.hpp>
0015 #include <boost/url/grammar/charset.hpp>
0016 #include <boost/url/grammar/error.hpp>
0017 #include <boost/url/grammar/type_traits.hpp>
0018 #include <type_traits>
0019 
0020 namespace boost {
0021 namespace urls {
0022 namespace grammar {
0023 
0024 /** Match a character literal
0025 
0026     This matches the specified character.
0027     The value is a reference to the character
0028     in the underlying buffer, expressed as a
0029     `core::string_view`. The function @ref squelch
0030     may be used to turn this into `void` instead.
0031     If there is no more input, the error code
0032     @ref error::need_more is returned.
0033 
0034     @par Value Type
0035     @code
0036     using value_type = core::string_view;
0037     @endcode
0038 
0039     @par Example
0040     Rules are used with the function @ref parse.
0041     @code
0042     system::result< core::string_view > rv = parse( ".", delim_rule('.') );
0043     @endcode
0044 
0045     @par BNF
0046     @code
0047     char        = %00-FF
0048     @endcode
0049 
0050     @param ch The character to match
0051 
0052     @see
0053         @ref parse,
0054         @ref squelch.
0055 */
0056 #ifdef BOOST_URL_DOCS
0057 constexpr
0058 __implementation_defined__
0059 delim_rule( char ch ) noexcept;
0060 #else
0061 struct ch_delim_rule
0062 {
0063     using value_type = core::string_view;
0064 
0065     constexpr
0066     ch_delim_rule(char ch) noexcept
0067         : ch_(ch)
0068     {
0069     }
0070 
0071     BOOST_URL_DECL
0072     system::result<value_type>
0073     parse(
0074         char const*& it,
0075         char const* end) const noexcept;
0076 
0077 private:
0078     char ch_;
0079 };
0080 
0081 constexpr
0082 ch_delim_rule
0083 delim_rule( char ch ) noexcept
0084 {
0085     return ch_delim_rule(ch);
0086 }
0087 #endif
0088 
0089 //------------------------------------------------
0090 
0091 /** Match a single character from a character set
0092 
0093     This matches exactly one character which
0094     belongs to the specified character set.
0095     The value is a reference to the character
0096     in the underlying buffer, expressed as a
0097     `core::string_view`. The function @ref squelch
0098     may be used to turn this into `void` instead.
0099     If there is no more input, the error code
0100     @ref error::need_more is returned.
0101 
0102     @par Value Type
0103     @code
0104     using value_type = core::string_view;
0105     @endcode
0106 
0107     @par Example
0108     Rules are used with the function @ref parse.
0109     @code
0110     system::result< core::string_view > rv = parse( "X", delim_rule( alpha_chars ) );
0111     @endcode
0112 
0113     @param cs The character set to use.
0114 
0115     @see
0116         @ref alpha_chars,
0117         @ref parse,
0118         @ref squelch.
0119 */
0120 #ifdef BOOST_URL_DOCS
0121 template<class CharSet>
0122 constexpr
0123 __implementation_defined__
0124 delim_rule( CharSet const& cs ) noexcept;
0125 #else
0126 template<class CharSet>
0127 struct cs_delim_rule
0128 {
0129     using value_type = core::string_view;
0130 
0131     constexpr
0132     cs_delim_rule(
0133         CharSet const& cs) noexcept
0134         : cs_(cs)
0135     {
0136     }
0137 
0138     system::result<value_type>
0139     parse(
0140         char const*& it,
0141         char const* end) const noexcept
0142     {
0143         if(it == end)
0144         {
0145             // end
0146             BOOST_URL_RETURN_EC(
0147                 error::need_more);
0148         }
0149         if(! cs_(*it))
0150         {
0151             // wrong character
0152             BOOST_URL_RETURN_EC(
0153                 error::mismatch);
0154         }
0155         return core::string_view{
0156             it++, 1 };
0157     }
0158 
0159 private:
0160     CharSet cs_;
0161 };
0162 
0163 template<class CharSet>
0164 constexpr
0165 typename std::enable_if<
0166     ! std::is_convertible<
0167         CharSet, char>::value,
0168     cs_delim_rule<CharSet>>::type
0169 delim_rule(
0170     CharSet const& cs) noexcept
0171 {
0172     // If you get a compile error here it
0173     // means that your type does not meet
0174     // the requirements for a CharSet.
0175     // Please consult the documentation.
0176     static_assert(
0177         is_charset<CharSet>::value,
0178         "CharSet requirements not met");
0179 
0180     return cs_delim_rule<CharSet>(cs);
0181 }
0182 #endif
0183 
0184 } // grammar
0185 } // urls
0186 } // boost
0187 
0188 #endif