![]() |
|
|||
File indexing completed on 2025-09-15 08:53:57
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 namespace implementation_defined { 0062 struct hexdig_chars_t 0063 { 0064 /** Determine if a character is a hexadecimal digit 0065 0066 @param c The character to test 0067 @return `true` if `c` is a hexadecimal digit. 0068 */ 0069 constexpr 0070 bool 0071 operator()(char c) const noexcept 0072 { 0073 return 0074 (c >= '0' && c <= '9') || 0075 (c >= 'A' && c <= 'F') || 0076 (c >= 'a' && c <= 'f'); 0077 } 0078 0079 #ifdef BOOST_URL_USE_SSE2 0080 char const* 0081 find_if( 0082 char const* first, 0083 char const* last) const noexcept 0084 { 0085 return detail::find_if_pred( 0086 *this, first, last); 0087 } 0088 0089 char const* 0090 find_if_not( 0091 char const* first, 0092 char const* last) const noexcept 0093 { 0094 return detail::find_if_not_pred( 0095 *this, first, last); 0096 } 0097 #endif 0098 }; 0099 } 0100 0101 /** The set of hexadecimal digits 0102 0103 @par Example 0104 Character sets are used with rules and the 0105 functions @ref find_if and @ref find_if_not. 0106 @code 0107 system::result< core::string_view > rv = parse( "8086FC19", token_rule( hexdig_chars ) ); 0108 @endcode 0109 0110 @par BNF 0111 @code 0112 HEXDIG = DIGIT 0113 / "A" / "B" / "C" / "D" / "E" / "F" 0114 / "a" / "b" / "c" / "d" / "e" / "f" 0115 @endcode 0116 0117 @note The RFCs are inconsistent on the case 0118 sensitivity of hexadecimal digits. Existing 0119 uses suggest case-insensitivity is a de-facto 0120 standard. 0121 0122 @par Specification 0123 @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1" 0124 >B.1. Core Rules (rfc5234)</a> 0125 @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-1.2" 0126 >1.2. Syntax Notation (rfc7230)</a> 0127 @li <a href="https://datatracker.ietf.org/doc/html/rfc5952#section-2.3" 0128 >2.3. Uppercase or Lowercase (rfc5952)</a> 0129 @li <a href="https://datatracker.ietf.org/doc/html/rfc5952#section-4.3" 0130 >4.3. Lowercase (rfc5952)</a> 0131 0132 @see 0133 @ref find_if, 0134 @ref find_if_not, 0135 @ref hexdig_value, 0136 @ref parse, 0137 @ref token_rule. 0138 */ 0139 constexpr implementation_defined::hexdig_chars_t hexdig_chars{}; 0140 #endif 0141 0142 // VFALCO We can declare 0143 // these later if needed 0144 // 0145 //struct hexdig_upper_chars; 0146 //struct hexdig_lower_chars; 0147 0148 /** Return the decimal value of a hex character 0149 0150 This function returns the decimal 0151 value of a hexadecimal character, 0152 or -1 if the argument is not a 0153 valid hexadecimal digit. 0154 0155 @par BNF 0156 @code 0157 HEXDIG = DIGIT 0158 / "A" / "B" / "C" / "D" / "E" / "F" 0159 / "a" / "b" / "c" / "d" / "e" / "f" 0160 @endcode 0161 0162 @param ch The character to check 0163 0164 @return The decimal value or -1 0165 */ 0166 inline 0167 signed char 0168 hexdig_value(char ch) noexcept 0169 { 0170 // Idea for switch statement to 0171 // minimize emitted assembly from 0172 // Glen Fernandes 0173 signed char res; 0174 switch(ch) 0175 { 0176 default: res = -1; break; 0177 case '0': res = 0; break; 0178 case '1': res = 1; break; 0179 case '2': res = 2; break; 0180 case '3': res = 3; break; 0181 case '4': res = 4; break; 0182 case '5': res = 5; break; 0183 case '6': res = 6; break; 0184 case '7': res = 7; break; 0185 case '8': res = 8; break; 0186 case '9': res = 9; break; 0187 case 'a': case 'A': res = 10; break; 0188 case 'b': case 'B': res = 11; break; 0189 case 'c': case 'C': res = 12; break; 0190 case 'd': case 'D': res = 13; break; 0191 case 'e': case 'E': res = 14; break; 0192 case 'f': case 'F': res = 15; break; 0193 } 0194 return res; 0195 } 0196 0197 } // grammar 0198 } // urls 0199 } // boost 0200 0201 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |