alpha_chars.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_ALPHA_CHARS_HPP
  10. #define BOOST_URL_GRAMMAR_ALPHA_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 all letters
  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 > rv = parse( "JohnDoe", token_rule( alpha_chars ) );
  22. @endcode
  23. @par BNF
  24. @code
  25. ALPHA = %x41-5A / %x61-7A
  26. ; A-Z / a-z
  27. @endcode
  28. @par Specification
  29. @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#appendix-B.1"
  30. >B.1. Core Rules (rfc5234)</a>
  31. @see
  32. @ref find_if,
  33. @ref find_if_not,
  34. @ref parse,
  35. @ref token_rule.
  36. */
  37. #ifdef BOOST_URL_DOCS
  38. constexpr __implementation_defined__ alpha_chars;
  39. #else
  40. struct alpha_chars_t
  41. {
  42. constexpr
  43. alpha_chars_t() noexcept = default;
  44. constexpr
  45. bool
  46. operator()(char c) const noexcept
  47. {
  48. return
  49. (c >= 'A' && c <= 'Z') ||
  50. (c >= 'a' && c <= 'z');
  51. }
  52. #ifdef BOOST_URL_USE_SSE2
  53. char const*
  54. find_if(
  55. char const* first,
  56. char const* last) const noexcept
  57. {
  58. return detail::find_if_pred(
  59. *this, first, last);
  60. }
  61. char const*
  62. find_if_not(
  63. char const* first,
  64. char const* last) const noexcept
  65. {
  66. return detail::find_if_not_pred(
  67. *this, first, last);
  68. }
  69. #endif
  70. };
  71. /** A character set containing the alphabetical characters.
  72. @see
  73. @ref alpha_chars_t
  74. */
  75. constexpr alpha_chars_t alpha_chars{};
  76. #endif
  77. } // grammar
  78. } // urls
  79. } // boost
  80. #endif