ignore_case.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_IGNORE_CASE_HPP
  10. #define BOOST_URL_IGNORE_CASE_HPP
  11. #include <boost/url/detail/config.hpp>
  12. namespace boost {
  13. namespace urls {
  14. namespace implementation_defined {
  15. struct ignore_case_t {};
  16. }
  17. /** Ignore case when comparing
  18. This value may be optionally passed to
  19. functions accepting a parameter of type
  20. @ref ignore_case_param to indicate that
  21. comparisons should be case-insensitive.
  22. */
  23. BOOST_INLINE_CONSTEXPR
  24. implementation_defined::ignore_case_t
  25. ignore_case{};
  26. /** An optional parameter to determine case-sensitivity
  27. Functions may use parameters of this type
  28. to allow the user to optionally indicate
  29. that comparisons should be case-insensitive
  30. when the value @ref ignore_case is passed.
  31. @see
  32. @ref params_ref
  33. */
  34. class ignore_case_param
  35. {
  36. /** True if an algorithm should ignore case
  37. Functions accepting a parameter of type
  38. `ignore_case_param` can check `value`
  39. to determine if the caller has indicated
  40. that comparisons should ignore case.
  41. */
  42. bool value_ = false;
  43. public:
  44. /** Constructor
  45. By default, comparisons are
  46. case-sensitive.
  47. @par Example
  48. This function performs case-sensitive
  49. comparisons when called with no
  50. arguments:
  51. @code
  52. void f( ignore_case_param = {} );
  53. @endcode
  54. */
  55. constexpr
  56. ignore_case_param() noexcept = default;
  57. /** Constructor
  58. Construction from @ref ignore_case
  59. indicates that comparisons should
  60. be case-insensitive.
  61. The first parameter to this function
  62. should be the variable
  63. @ref ignore_case.
  64. @par Example
  65. When @ref ignore_case is passed as
  66. an argument, this function ignores
  67. case when performing comparisons:
  68. @code
  69. void f( ignore_case_param(ignore_case) );
  70. @endcode
  71. */
  72. constexpr
  73. ignore_case_param(
  74. implementation_defined::ignore_case_t) noexcept
  75. : value_(true)
  76. {
  77. }
  78. /** True if an algorithm should ignore case
  79. Values of type `ignore_case_param`
  80. evaluate to true when constructed
  81. with the constant @ref ignore_case.
  82. Otherwise, they are default-constructed
  83. and evaluate to `false`.
  84. @return `true` if case should be ignored
  85. */
  86. operator
  87. bool() const noexcept
  88. {
  89. return value_;
  90. }
  91. };
  92. } // urls
  93. } // boost
  94. #endif