regex_traits.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file regex_traits.hpp
  3. /// Includes the C regex traits or the CPP regex traits header file depending on the
  4. /// BOOST_XPRESSIVE_USE_C_TRAITS macro.
  5. //
  6. // Copyright 2008 Eric Niebler. Distributed under the Boost
  7. // Software License, Version 1.0. (See accompanying file
  8. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005
  10. #define BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005
  11. // MS compatible compilers support #pragma once
  12. #if defined(_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/type_traits/is_convertible.hpp>
  16. #include <boost/xpressive/detail/detail_fwd.hpp>
  17. #ifdef BOOST_XPRESSIVE_USE_C_TRAITS
  18. # include <boost/xpressive/traits/c_regex_traits.hpp>
  19. #else
  20. # include <boost/xpressive/traits/cpp_regex_traits.hpp>
  21. #endif
  22. namespace boost { namespace xpressive
  23. {
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // regex_traits_version_1_tag
  26. /// Tag used to denote that a traits class conforms to the version 1 traits
  27. /// interface.
  28. struct regex_traits_version_1_tag
  29. {
  30. };
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // regex_traits_version_2_tag
  33. /// Tag used to denote that a traits class conforms to the version 2 traits
  34. /// interface.
  35. struct regex_traits_version_2_tag
  36. : regex_traits_version_1_tag
  37. {
  38. };
  39. ///////////////////////////////////////////////////////////////////////////////
  40. // regex_traits_version_1_case_fold_tag DEPRECATED use has_fold_case trait
  41. /// INTERNAL ONLY
  42. ///
  43. struct regex_traits_version_1_case_fold_tag
  44. : regex_traits_version_1_tag
  45. {
  46. };
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // has_fold_case
  49. /// Trait used to denote that a traits class has the fold_case member function.
  50. template<typename Traits>
  51. struct has_fold_case
  52. : is_convertible<
  53. typename Traits::version_tag *
  54. , regex_traits_version_1_case_fold_tag *
  55. >
  56. {
  57. };
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // regex_traits
  60. /// Thin wrapper around the default regex_traits implementation, either
  61. /// cpp_regex_traits or c_regex_traits
  62. ///
  63. template<typename Char, typename Impl>
  64. struct regex_traits
  65. : Impl
  66. {
  67. typedef typename Impl::locale_type locale_type;
  68. regex_traits()
  69. : Impl()
  70. {
  71. }
  72. explicit regex_traits(locale_type const &loc)
  73. : Impl(loc)
  74. {
  75. }
  76. };
  77. ///////////////////////////////////////////////////////////////////////////////
  78. // lookup_classname
  79. /// INTERNAL ONLY
  80. template<typename Traits, std::size_t N>
  81. inline typename Traits::char_class_type
  82. lookup_classname(Traits const &traits, char const (&cname)[N], bool icase)
  83. {
  84. typename Traits::char_type name[N] = {0};
  85. for(std::size_t j = 0; j < N-1; ++j)
  86. {
  87. name[j] = traits.widen(cname[j]);
  88. }
  89. return traits.lookup_classname(name, name + N - 1, icase);
  90. }
  91. }}
  92. #endif