basic_chset.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Joel de Guzman
  3. Copyright (c) 2001-2003 Daniel Nuffer
  4. http://spirit.sourceforge.net/
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================*/
  9. #ifndef BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_HPP_EAN_10_04_2005
  10. #define BOOST_XPRESSIVE_SPIRIT_BASIC_CHSET_HPP_EAN_10_04_2005
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <bitset>
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/xpressive/detail/utility/chset/range_run.ipp>
  15. namespace boost { namespace xpressive { namespace detail
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. //
  19. // basic_chset: basic character set implementation using range_run
  20. //
  21. ///////////////////////////////////////////////////////////////////////////
  22. template<typename Char>
  23. struct basic_chset
  24. {
  25. basic_chset();
  26. basic_chset(basic_chset const &arg);
  27. bool empty() const;
  28. void set(Char from, Char to);
  29. template<typename Traits>
  30. void set(Char from, Char to, Traits const &tr);
  31. void set(Char c);
  32. template<typename Traits>
  33. void set(Char c, Traits const &tr);
  34. void clear(Char from, Char to);
  35. template<typename Traits>
  36. void clear(Char from, Char to, Traits const &tr);
  37. void clear(Char c);
  38. template<typename Traits>
  39. void clear(Char c, Traits const &tr);
  40. void clear();
  41. template<typename Traits>
  42. bool test(Char v, Traits const &tr, mpl::false_) const; // case-sensitive
  43. template<typename Traits>
  44. bool test(Char v, Traits const &tr, mpl::true_) const; // case-insensitive
  45. void inverse();
  46. void swap(basic_chset& x);
  47. basic_chset &operator |=(basic_chset const &x);
  48. basic_chset &operator &=(basic_chset const &x);
  49. basic_chset &operator -=(basic_chset const &x);
  50. basic_chset &operator ^=(basic_chset const &x);
  51. private:
  52. range_run<Char> rr_;
  53. };
  54. #if(CHAR_BIT == 8)
  55. ///////////////////////////////////////////////////////////////////////////
  56. //
  57. // basic_chset: specializations for 8 bit chars using std::bitset
  58. //
  59. ///////////////////////////////////////////////////////////////////////////
  60. template<typename Char>
  61. struct basic_chset_8bit
  62. {
  63. basic_chset_8bit();
  64. basic_chset_8bit(basic_chset_8bit const &arg);
  65. bool empty() const;
  66. void set(Char from, Char to);
  67. template<typename Traits>
  68. void set(Char from, Char to, Traits const &tr);
  69. void set(Char c);
  70. template<typename Traits>
  71. void set(Char c, Traits const &tr);
  72. void clear(Char from, Char to);
  73. template<typename Traits>
  74. void clear(Char from, Char to, Traits const &tr);
  75. void clear(Char c);
  76. template<typename Traits>
  77. void clear(Char c, Traits const &tr);
  78. void clear();
  79. template<typename Traits>
  80. bool test(Char v, Traits const &tr, mpl::false_) const; // case-sensitive
  81. template<typename Traits>
  82. bool test(Char v, Traits const &tr, mpl::true_) const; // case-insensitive
  83. void inverse();
  84. void swap(basic_chset_8bit& x);
  85. basic_chset_8bit &operator |=(basic_chset_8bit const &x);
  86. basic_chset_8bit &operator &=(basic_chset_8bit const &x);
  87. basic_chset_8bit &operator -=(basic_chset_8bit const &x);
  88. basic_chset_8bit &operator ^=(basic_chset_8bit const &x);
  89. std::bitset<256> const &base() const;
  90. private:
  91. std::bitset<256> bset_; // BUGBUG range-checking slows this down
  92. };
  93. /////////////////////////////////
  94. template<>
  95. struct basic_chset<char>
  96. : basic_chset_8bit<char>
  97. {
  98. };
  99. /////////////////////////////////
  100. template<>
  101. struct basic_chset<signed char>
  102. : basic_chset_8bit<signed char>
  103. {
  104. };
  105. /////////////////////////////////
  106. template<>
  107. struct basic_chset<unsigned char>
  108. : basic_chset_8bit<unsigned char>
  109. {
  110. };
  111. #endif
  112. ///////////////////////////////////////////////////////////////////////////////
  113. // is_narrow_char
  114. template<typename Char>
  115. struct is_narrow_char
  116. : mpl::false_
  117. {};
  118. template<>
  119. struct is_narrow_char<char>
  120. : mpl::true_
  121. {};
  122. template<>
  123. struct is_narrow_char<signed char>
  124. : mpl::true_
  125. {};
  126. template<>
  127. struct is_narrow_char<unsigned char>
  128. : mpl::true_
  129. {};
  130. ///////////////////////////////////////////////////////////////////////////////
  131. // helpers
  132. template<typename Char, typename Traits>
  133. void set_char(basic_chset<Char> &chset, Char ch, Traits const &tr, bool icase);
  134. template<typename Char, typename Traits>
  135. void set_range(basic_chset<Char> &chset, Char from, Char to, Traits const &tr, bool icase);
  136. template<typename Char, typename Traits>
  137. void set_class(basic_chset<Char> &chset, typename Traits::char_class_type char_class, bool no, Traits const &tr);
  138. }}} // namespace boost::xpressive::detail
  139. #endif