unsigned_rule.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/core/detail/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. template<class Unsigned>
  43. struct unsigned_rule
  44. {
  45. BOOST_CORE_STATIC_ASSERT(
  46. std::numeric_limits<
  47. Unsigned>::is_integer &&
  48. ! std::numeric_limits<
  49. Unsigned>::is_signed);
  50. using value_type = Unsigned;
  51. auto
  52. parse(
  53. char const*& it,
  54. char const* end
  55. ) const noexcept ->
  56. system::result<value_type>;
  57. };
  58. } // grammar
  59. } // urls
  60. } // boost
  61. #include <boost/url/grammar/impl/unsigned_rule.hpp>
  62. #endif