Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:07:54

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 namespace implementation_defined {
0025 struct ch_delim_rule
0026 {
0027     using value_type = core::string_view;
0028 
0029     constexpr
0030     ch_delim_rule(char ch) noexcept
0031         : ch_(ch)
0032     {
0033     }
0034 
0035     BOOST_URL_DECL
0036     system::result<value_type>
0037     parse(
0038         char const*& it,
0039         char const* end) const noexcept;
0040 
0041 private:
0042     char ch_;
0043 };
0044 } // implementation_defined
0045 
0046 /** Match a character literal
0047 
0048     This matches the specified character.
0049     The value is a reference to the character
0050     in the underlying buffer, expressed as a
0051     `core::string_view`. The function @ref squelch
0052     may be used to turn this into `void` instead.
0053     If there is no more input, the error code
0054     @ref error::need_more is returned.
0055 
0056     @par Value Type
0057     @code
0058     using value_type = core::string_view;
0059     @endcode
0060 
0061     @par Example
0062     Rules are used with the function @ref parse.
0063     @code
0064     system::result< core::string_view > rv = parse( ".", delim_rule('.') );
0065     @endcode
0066 
0067     @par BNF
0068     @code
0069     char        = %00-FF
0070     @endcode
0071 
0072     @param ch The character to match
0073     @return A rule which matches the character.
0074 
0075     @see
0076         @ref parse,
0077         @ref squelch.
0078 */
0079 constexpr
0080 implementation_defined::ch_delim_rule
0081 delim_rule( char ch ) noexcept
0082 {
0083     return {ch};
0084 }
0085 
0086 //------------------------------------------------
0087 
0088 namespace implementation_defined {
0089 template<class CharSet>
0090 struct cs_delim_rule
0091 {
0092     using value_type = core::string_view;
0093 
0094     constexpr
0095     cs_delim_rule(
0096         CharSet const& cs) noexcept
0097         : cs_(cs)
0098     {
0099     }
0100 
0101     system::result<value_type>
0102     parse(
0103         char const*& it,
0104         char const* end) const noexcept
0105     {
0106         if(it == end)
0107         {
0108             // end
0109             BOOST_URL_RETURN_EC(
0110                 error::need_more);
0111         }
0112         if(! cs_(*it))
0113         {
0114             // wrong character
0115             BOOST_URL_RETURN_EC(
0116                 error::mismatch);
0117         }
0118         return core::string_view{
0119             it++, 1 };
0120     }
0121 
0122 private:
0123     CharSet cs_;
0124 };
0125 } // implementation_defined
0126 
0127 /** Match a single character from a character set
0128 
0129     This matches exactly one character which
0130     belongs to the specified character set.
0131     The value is a reference to the character
0132     in the underlying buffer, expressed as a
0133     `core::string_view`. The function @ref squelch
0134     may be used to turn this into `void` instead.
0135     If there is no more input, the error code
0136     @ref error::need_more is returned.
0137 
0138     @par Value Type
0139     @code
0140     using value_type = core::string_view;
0141     @endcode
0142 
0143     @par Example
0144     Rules are used with the function @ref parse.
0145     @code
0146     system::result< core::string_view > rv = parse( "X", delim_rule( alpha_chars ) );
0147     @endcode
0148 
0149     @param cs The character set to use.
0150     @return A rule which matches a single character from the set.
0151 
0152     @see
0153         @ref alpha_chars,
0154         @ref parse,
0155         @ref squelch.
0156 */
0157 template<BOOST_URL_CONSTRAINT(CharSet) CS>
0158 constexpr
0159 typename std::enable_if<
0160     ! std::is_convertible<
0161         CS, char>::value,
0162     implementation_defined::cs_delim_rule<CS>>::type
0163 delim_rule(
0164     CS const& cs) noexcept
0165 {
0166     // If you get a compile error here it
0167     // means that your type does not meet
0168     // the requirements for a CharSet.
0169     // Please consult the documentation.
0170     static_assert(
0171         is_charset<CS>::value,
0172         "CharSet requirements not met");
0173 
0174     return implementation_defined::cs_delim_rule<CS>(cs);
0175 }
0176 
0177 } // grammar
0178 } // urls
0179 } // boost
0180 
0181 #endif