any_char.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_X3_ANY_CHAR_APRIL_16_2006_1051AM)
  7. #define BOOST_SPIRIT_X3_ANY_CHAR_APRIL_16_2006_1051AM
  8. #include <boost/type_traits/extent.hpp>
  9. #include <boost/spirit/home/x3/char/literal_char.hpp>
  10. #include <boost/spirit/home/x3/char/char_set.hpp>
  11. namespace boost { namespace spirit { namespace x3
  12. {
  13. template <typename Encoding>
  14. struct any_char : char_parser<any_char<Encoding>>
  15. {
  16. typedef typename Encoding::char_type char_type;
  17. typedef Encoding encoding;
  18. typedef char_type attribute_type;
  19. static bool const has_attribute = true;
  20. template <typename Char, typename Context>
  21. bool test(Char ch_, Context const&) const
  22. {
  23. return encoding::ischar(ch_);
  24. }
  25. template <typename Char>
  26. literal_char<Encoding> operator()(Char ch) const
  27. {
  28. return { ch };
  29. }
  30. template <typename Char>
  31. literal_char<Encoding> operator()(const Char (&ch)[2]) const
  32. {
  33. return { ch[0] };
  34. }
  35. template <typename Char, std::size_t N>
  36. char_set<Encoding> operator()(const Char (&ch)[N]) const
  37. {
  38. return { ch };
  39. }
  40. template <typename Char>
  41. char_range<Encoding> operator()(Char from, Char to) const
  42. {
  43. return { from, to };
  44. }
  45. template <typename Char>
  46. char_range<Encoding> operator()(Char (&from)[2], Char (&to)[2]) const
  47. {
  48. return { static_cast<char_type>(from[0]), static_cast<char_type>(to[0]) };
  49. }
  50. template <typename Char>
  51. char_set<Encoding> operator()(std::basic_string<Char> const& s) const
  52. {
  53. return { s };
  54. }
  55. };
  56. }}}
  57. #endif