char.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_CHAR_APRIL_16_2006_1051AM)
  7. #define BOOST_SPIRIT_X3_CHAR_APRIL_16_2006_1051AM
  8. #include <boost/spirit/home/x3/char/any_char.hpp>
  9. #include <boost/spirit/home/support/char_encoding/ascii.hpp>
  10. #include <boost/spirit/home/support/char_encoding/iso8859_1.hpp>
  11. #include <boost/spirit/home/support/char_encoding/standard.hpp>
  12. #include <boost/spirit/home/support/char_encoding/standard_wide.hpp>
  13. namespace boost { namespace spirit { namespace x3
  14. {
  15. namespace standard
  16. {
  17. typedef any_char<char_encoding::standard> char_type;
  18. constexpr auto char_ = char_type{};
  19. constexpr literal_char<char_encoding::standard, unused_type>
  20. lit(char ch)
  21. {
  22. return { ch };
  23. }
  24. constexpr literal_char<char_encoding::standard, unused_type>
  25. lit(wchar_t ch)
  26. {
  27. return { ch };
  28. }
  29. }
  30. using standard::char_type;
  31. using standard::char_;
  32. using standard::lit;
  33. #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
  34. namespace standard_wide
  35. {
  36. typedef any_char<char_encoding::standard_wide> char_type;
  37. constexpr auto char_ = char_type{};
  38. constexpr literal_char<char_encoding::standard_wide, unused_type>
  39. lit(wchar_t ch)
  40. {
  41. return { ch };
  42. }
  43. }
  44. #endif
  45. namespace ascii
  46. {
  47. typedef any_char<char_encoding::ascii> char_type;
  48. constexpr auto char_ = char_type{};
  49. constexpr literal_char<char_encoding::ascii, unused_type>
  50. lit(char ch)
  51. {
  52. return { ch };
  53. }
  54. constexpr literal_char<char_encoding::ascii, unused_type>
  55. lit(wchar_t ch)
  56. {
  57. return { ch };
  58. }
  59. }
  60. namespace iso8859_1
  61. {
  62. typedef any_char<char_encoding::iso8859_1> char_type;
  63. constexpr auto char_ = char_type{};
  64. constexpr literal_char<char_encoding::iso8859_1, unused_type>
  65. lit(char ch)
  66. {
  67. return { ch };
  68. }
  69. constexpr literal_char<char_encoding::iso8859_1, unused_type>
  70. lit(wchar_t ch)
  71. {
  72. return { ch };
  73. }
  74. }
  75. namespace extension
  76. {
  77. template <>
  78. struct as_parser<char>
  79. {
  80. typedef literal_char<
  81. char_encoding::standard, unused_type>
  82. type;
  83. typedef type value_type;
  84. static constexpr type call(char ch)
  85. {
  86. return { ch };
  87. }
  88. };
  89. #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
  90. template <>
  91. struct as_parser<wchar_t>
  92. {
  93. typedef literal_char<
  94. char_encoding::standard_wide, unused_type>
  95. type;
  96. typedef type value_type;
  97. static constexpr type call(wchar_t ch)
  98. {
  99. return { ch };
  100. }
  101. };
  102. #endif
  103. template <>
  104. struct as_parser<char [2]>
  105. {
  106. typedef literal_char<
  107. char_encoding::standard, unused_type>
  108. type;
  109. typedef type value_type;
  110. static constexpr type call(char const ch[])
  111. {
  112. return { ch[0] };
  113. }
  114. };
  115. #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
  116. template <>
  117. struct as_parser<wchar_t [2]>
  118. {
  119. typedef literal_char<
  120. char_encoding::standard_wide, unused_type>
  121. type;
  122. typedef type value_type;
  123. static constexpr type call(wchar_t const ch[] )
  124. {
  125. return { ch[0] };
  126. }
  127. };
  128. #endif
  129. }
  130. }}}
  131. #endif