alnum_chars.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/url
  8. //
  9. #ifndef BOOST_URL_GRAMMAR_ALNUM_CHARS_HPP
  10. #define BOOST_URL_GRAMMAR_ALNUM_CHARS_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/url/grammar/detail/charset.hpp>
  13. namespace boost {
  14. namespace urls {
  15. namespace grammar {
  16. namespace implementation_defined {
  17. struct alnum_chars_t
  18. {
  19. constexpr
  20. bool
  21. operator()(char c) const noexcept
  22. {
  23. return
  24. (c >= '0' && c <= '9') ||
  25. (c >= 'A' && c <= 'Z') ||
  26. (c >= 'a' && c <= 'z');
  27. }
  28. #ifdef BOOST_URL_USE_SSE2
  29. char const*
  30. find_if(
  31. char const* first,
  32. char const* last) const noexcept
  33. {
  34. return detail::find_if_pred(
  35. *this, first, last);
  36. }
  37. char const*
  38. find_if_not(
  39. char const* first,
  40. char const* last) const noexcept
  41. {
  42. return detail::find_if_not_pred(
  43. *this, first, last);
  44. }
  45. #endif
  46. };
  47. } // implementation_defined
  48. /** The set of letters and digits
  49. @par Example
  50. Character sets are used with rules and the
  51. functions @ref find_if and @ref find_if_not.
  52. @code
  53. system::result< core::string_view > = parse( "Johnny42", token_rule( alnumchars ) );
  54. @endcode
  55. @par BNF
  56. @code
  57. ALNUM = ALPHA / DIGIT
  58. ALPHA = %x41-5A / %x61-7A
  59. ; A-Z / a-z
  60. DIGIT = %x30-39
  61. ; 0-9
  62. @endcode
  63. @par Specification
  64. @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1"
  65. >B.1. Core Rules (rfc5234)</a>
  66. @see
  67. @ref find_if,
  68. @ref find_if_not,
  69. @ref parse,
  70. @ref token_rule.
  71. */
  72. constexpr implementation_defined::alnum_chars_t alnum_chars{};
  73. } // grammar
  74. } // urls
  75. } // boost
  76. #endif