Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // Copyright (c) 2021 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_HEXDIG_CHARS_HPP
0011 #define BOOST_URL_GRAMMAR_HEXDIG_CHARS_HPP
0012 
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/grammar/detail/charset.hpp>
0015 
0016 namespace boost {
0017 namespace urls {
0018 namespace grammar {
0019 
0020 /** The set of hexadecimal digits
0021 
0022     @par Example
0023     Character sets are used with rules and the
0024     functions @ref find_if and @ref find_if_not.
0025     @code
0026     system::result< core::string_view > rv = parse( "8086FC19", token_rule( hexdig_chars ) );
0027     @endcode
0028 
0029     @par BNF
0030     @code
0031     HEXDIG      = DIGIT
0032                 / "A" / "B" / "C" / "D" / "E" / "F"
0033                 / "a" / "b" / "c" / "d" / "e" / "f"
0034     @endcode
0035 
0036     @note The RFCs are inconsistent on the case
0037     sensitivity of hexadecimal digits. Existing
0038     uses suggest case-insensitivity is a de-facto
0039     standard.
0040 
0041     @par Specification
0042     @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1"
0043         >B.1. Core Rules (rfc5234)</a>
0044     @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-1.2"
0045         >1.2. Syntax Notation (rfc7230)</a>
0046     @li <a href="https://datatracker.ietf.org/doc/html/rfc5952#section-2.3"
0047         >2.3. Uppercase or Lowercase (rfc5952)</a>
0048     @li <a href="https://datatracker.ietf.org/doc/html/rfc5952#section-4.3"
0049         >4.3. Lowercase (rfc5952)</a>
0050 
0051     @see
0052         @ref find_if,
0053         @ref find_if_not,
0054         @ref hexdig_value,
0055         @ref parse,
0056         @ref token_rule.
0057 */
0058 #ifdef BOOST_URL_DOCS
0059 constexpr __implementation_defined__ hexdig_chars;
0060 #else
0061 struct hexdig_chars_t
0062 {
0063     /** Return true if c is in the character set.
0064     */
0065     constexpr
0066     bool
0067     operator()(char c) const noexcept
0068     {
0069         return
0070             (c >= '0' && c <= '9') ||
0071             (c >= 'A' && c <= 'F') ||
0072             (c >= 'a' && c <= 'f');
0073     }
0074 
0075 #ifdef BOOST_URL_USE_SSE2
0076     char const*
0077     find_if(
0078         char const* first,
0079         char const* last) const noexcept
0080     {
0081         return detail::find_if_pred(
0082             *this, first, last);
0083     }
0084 
0085     char const*
0086     find_if_not(
0087         char const* first,
0088         char const* last) const noexcept
0089     {
0090         return detail::find_if_not_pred(
0091             *this, first, last);
0092     }
0093 #endif
0094 };
0095 
0096 constexpr hexdig_chars_t hexdig_chars{};
0097 #endif
0098 
0099 // VFALCO We can declare
0100 // these later if needed
0101 //
0102 //struct hexdig_upper_chars;
0103 //struct hexdig_lower_chars;
0104 
0105 /** Return the decimal value of a hex character
0106 
0107     This function returns the decimal
0108     value of a hexadecimal character,
0109     or -1 if the argument is not a
0110     valid hexadecimal digit.
0111 
0112     @par BNF
0113     @code
0114     HEXDIG      = DIGIT
0115                 / "A" / "B" / "C" / "D" / "E" / "F"
0116                 / "a" / "b" / "c" / "d" / "e" / "f"
0117     @endcode
0118 
0119     @param ch The character to check
0120 
0121     @return The decimal value or -1
0122 */
0123 inline
0124 signed char
0125 hexdig_value(char ch) noexcept
0126 {
0127     // Idea for switch statement to
0128     // minimize emitted assembly from
0129     // Glen Fernandes
0130     signed char res;
0131     switch(ch)
0132     {
0133     default:            res = -1; break;
0134     case '0':           res =  0; break;
0135     case '1':           res =  1; break;
0136     case '2':           res =  2; break;
0137     case '3':           res =  3; break;
0138     case '4':           res =  4; break;
0139     case '5':           res =  5; break;
0140     case '6':           res =  6; break;
0141     case '7':           res =  7; break;
0142     case '8':           res =  8; break;
0143     case '9':           res =  9; break;
0144     case 'a': case 'A': res = 10; break;
0145     case 'b': case 'B': res = 11; break;
0146     case 'c': case 'C': res = 12; break;
0147     case 'd': case 'D': res = 13; break;
0148     case 'e': case 'E': res = 14; break;
0149     case 'f': case 'F': res = 15; break;
0150     }
0151     return res;
0152 }
0153 
0154 } // grammar
0155 } // urls
0156 } // boost
0157 
0158 #endif