alnum_chars.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /** The set of letters and digits
  17. @par Example
  18. Character sets are used with rules and the
  19. functions @ref find_if and @ref find_if_not.
  20. @code
  21. system::result< core::string_view > = parse( "Johnny42", token_rule( alnumchars ) );
  22. @endcode
  23. @par BNF
  24. @code
  25. ALNUM = ALPHA / DIGIT
  26. ALPHA = %x41-5A / %x61-7A
  27. ; A-Z / a-z
  28. DIGIT = %x30-39
  29. ; 0-9
  30. @endcode
  31. @par Specification
  32. @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1"
  33. >B.1. Core Rules (rfc5234)</a>
  34. @see
  35. @ref find_if,
  36. @ref find_if_not,
  37. @ref parse,
  38. @ref token_rule.
  39. */
  40. #ifdef BOOST_URL_DOCS
  41. constexpr __implementation_defined__ alnum_chars;
  42. #else
  43. struct alnum_chars_t
  44. {
  45. constexpr
  46. bool
  47. operator()(char c) const noexcept
  48. {
  49. return
  50. (c >= '0' && c <= '9') ||
  51. (c >= 'A' && c <= 'Z') ||
  52. (c >= 'a' && c <= 'z');
  53. }
  54. #ifdef BOOST_URL_USE_SSE2
  55. char const*
  56. find_if(
  57. char const* first,
  58. char const* last) const noexcept
  59. {
  60. return detail::find_if_pred(
  61. *this, first, last);
  62. }
  63. char const*
  64. find_if_not(
  65. char const* first,
  66. char const* last) const noexcept
  67. {
  68. return detail::find_if_not_pred(
  69. *this, first, last);
  70. }
  71. #endif
  72. };
  73. constexpr alnum_chars_t alnum_chars{};
  74. #endif
  75. } // grammar
  76. } // urls
  77. } // boost
  78. #endif