unsigned_rule.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. // Copyright (c) 2022 Alan de Freitas (alandefreitas at gmail dot com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/boostorg/url
  9. //
  10. #ifndef BOOST_URL_GRAMMAR_UNSIGNED_RULE_HPP
  11. #define BOOST_URL_GRAMMAR_UNSIGNED_RULE_HPP
  12. #include <boost/url/detail/config.hpp>
  13. #include <boost/url/error_types.hpp>
  14. #include <boost/url/grammar/charset.hpp>
  15. #include <boost/core/detail/string_view.hpp>
  16. #include <boost/static_assert.hpp>
  17. #include <limits>
  18. #include <type_traits>
  19. namespace boost {
  20. namespace urls {
  21. namespace grammar {
  22. /** Match an unsigned decimal
  23. Extra leading zeroes are disallowed.
  24. @par Value Type
  25. @code
  26. using value_type = Unsigned;
  27. @endcode
  28. @par Example
  29. Rules are used with the function @ref parse.
  30. @code
  31. system::result< unsigned short > rv = parse( "32767", unsigned_rule< unsigned short >{} );
  32. @endcode
  33. @par BNF
  34. @code
  35. unsigned = "0" / ( ["1"..."9"] *DIGIT )
  36. @endcode
  37. @tparam Unsigned The unsigned integer type used
  38. to store the result.
  39. @see
  40. @ref grammar::parse.
  41. */
  42. #ifdef BOOST_URL_DOCS
  43. template<class Unsigned>
  44. struct unsigned_rule;
  45. #else
  46. template<class Unsigned>
  47. struct unsigned_rule
  48. {
  49. BOOST_STATIC_ASSERT(
  50. std::numeric_limits<
  51. Unsigned>::is_integer &&
  52. ! std::numeric_limits<
  53. Unsigned>::is_signed);
  54. using value_type = Unsigned;
  55. auto
  56. parse(
  57. char const*& it,
  58. char const* end
  59. ) const noexcept ->
  60. system::result<value_type>;
  61. };
  62. #endif
  63. } // grammar
  64. } // urls
  65. } // boost
  66. #include <boost/url/grammar/impl/unsigned_rule.hpp>
  67. #endif