Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:37

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 #if !defined(BOOST_SPIRIT_X3_LITERAL_STRING_APR_18_2006_1125PM)
0008 #define BOOST_SPIRIT_X3_LITERAL_STRING_APR_18_2006_1125PM
0009 
0010 #include <boost/spirit/home/x3/core/parser.hpp>
0011 #include <boost/spirit/home/x3/core/skip_over.hpp>
0012 #include <boost/spirit/home/x3/string/detail/string_parse.hpp>
0013 #include <boost/spirit/home/x3/support/no_case.hpp>
0014 #include <boost/spirit/home/x3/support/utility/utf8.hpp>
0015 #include <boost/spirit/home/support/char_encoding/ascii.hpp>
0016 #include <boost/spirit/home/support/char_encoding/standard.hpp>
0017 #include <boost/spirit/home/support/char_encoding/standard_wide.hpp>
0018 
0019 #include <boost/type_traits/is_same.hpp>
0020 #include <boost/type_traits/add_reference.hpp>
0021 #include <string>
0022 
0023 namespace boost { namespace spirit { namespace x3
0024 {
0025     template <typename String, typename Encoding,
0026         typename Attribute = std::basic_string<typename Encoding::char_type>>
0027     struct literal_string : parser<literal_string<String, Encoding, Attribute>>
0028     {
0029         typedef typename Encoding::char_type char_type;
0030         typedef Encoding encoding;
0031         typedef Attribute attribute_type;
0032         static bool const has_attribute =
0033             !is_same<unused_type, attribute_type>::value;
0034         static bool const handles_container = has_attribute;
0035 
0036         constexpr literal_string(typename add_reference< typename add_const<String>::type >::type str)
0037           : str(str)
0038         {}
0039 
0040         template <typename Iterator, typename Context, typename Attribute_>
0041         bool parse(Iterator& first, Iterator const& last
0042           , Context const& context, unused_type, Attribute_& attr) const
0043         {
0044             x3::skip_over(first, last, context);
0045             return detail::string_parse(str, first, last, attr, get_case_compare<encoding>(context));
0046         }
0047 
0048         String str;
0049     };
0050 
0051     namespace standard
0052     {
0053         constexpr literal_string<char const*, char_encoding::standard>
0054         string(char const* s)
0055         {
0056             return { s };
0057         }
0058 
0059         inline literal_string<std::basic_string<char>, char_encoding::standard>
0060         string(std::basic_string<char> const& s)
0061         {
0062             return { s };
0063         }
0064 
0065         inline constexpr literal_string<char const*, char_encoding::standard, unused_type>
0066         lit(char const* s)
0067         {
0068             return { s };
0069         }
0070 
0071         template <typename Char>
0072         literal_string<std::basic_string<Char>, char_encoding::standard, unused_type>
0073         lit(std::basic_string<Char> const& s)
0074         {
0075             return { s };
0076         }
0077     }
0078 
0079 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
0080     namespace standard_wide
0081     {
0082         constexpr literal_string<wchar_t const*, char_encoding::standard_wide>
0083         string(wchar_t const* s)
0084         {
0085             return { s };
0086         }
0087 
0088         inline literal_string<std::basic_string<wchar_t>, char_encoding::standard_wide>
0089         string(std::basic_string<wchar_t> const& s)
0090         {
0091             return { s };
0092         }
0093 
0094         constexpr literal_string<wchar_t const*, char_encoding::standard_wide, unused_type>
0095         lit(wchar_t const* s)
0096         {
0097             return { s };
0098         }
0099 
0100         inline literal_string<std::basic_string<wchar_t>, char_encoding::standard_wide, unused_type>
0101         lit(std::basic_string<wchar_t> const& s)
0102         {
0103             return { s };
0104         }
0105     }
0106 #endif
0107 
0108 #if defined(BOOST_SPIRIT_X3_UNICODE)
0109     namespace unicode
0110     {
0111         constexpr literal_string<char32_t const*, char_encoding::unicode>
0112         string(char32_t const* s)
0113         {
0114             return { s };
0115         }
0116 
0117         inline literal_string<std::basic_string<char32_t>, char_encoding::unicode>
0118         string(std::basic_string<char32_t> const& s)
0119         {
0120             return { s };
0121         }
0122 
0123         constexpr literal_string<char32_t const*, char_encoding::unicode, unused_type>
0124         lit(char32_t const* s)
0125         {
0126             return { s };
0127         }
0128 
0129         inline literal_string<std::basic_string<char32_t>, char_encoding::unicode, unused_type>
0130         lit(std::basic_string<char32_t> const& s)
0131         {
0132             return { s };
0133         }
0134     }
0135 #endif
0136 
0137     namespace ascii
0138     {
0139         constexpr literal_string<wchar_t const*, char_encoding::ascii>
0140         string(wchar_t const* s)
0141         {
0142             return { s };
0143         }
0144 
0145         inline literal_string<std::basic_string<wchar_t>, char_encoding::ascii>
0146         string(std::basic_string<wchar_t> const& s)
0147         {
0148             return { s };
0149         }
0150 
0151         constexpr literal_string<char const*, char_encoding::ascii, unused_type>
0152         lit(char const* s)
0153         {
0154             return { s };
0155         }
0156 
0157         template <typename Char>
0158         literal_string<std::basic_string<Char>, char_encoding::ascii, unused_type>
0159         lit(std::basic_string<Char> const& s)
0160         {
0161             return { s };
0162         }
0163     }
0164 
0165     namespace iso8859_1
0166     {
0167         constexpr literal_string<wchar_t const*, char_encoding::iso8859_1>
0168         string(wchar_t const* s)
0169         {
0170             return { s };
0171         }
0172 
0173         inline literal_string<std::basic_string<wchar_t>, char_encoding::iso8859_1>
0174         string(std::basic_string<wchar_t> const& s)
0175         {
0176             return { s };
0177         }
0178 
0179         constexpr literal_string<char const*, char_encoding::iso8859_1, unused_type>
0180         lit(char const* s)
0181         {
0182             return { s };
0183         }
0184 
0185         template <typename Char>
0186         literal_string<std::basic_string<Char>, char_encoding::iso8859_1, unused_type>
0187         lit(std::basic_string<Char> const& s)
0188         {
0189             return { s };
0190         }
0191     }
0192 
0193     using standard::string;
0194     using standard::lit;
0195 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
0196     using standard_wide::string;
0197     using standard_wide::lit;
0198 #endif
0199 
0200     namespace extension
0201     {
0202         template <int N>
0203         struct as_parser<char[N]>
0204         {
0205             typedef literal_string<
0206                 char const*, char_encoding::standard, unused_type>
0207             type;
0208 
0209             typedef type value_type;
0210 
0211             static constexpr type call(char const* s)
0212             {
0213                 return type(s);
0214             }
0215         };
0216 
0217         template <int N>
0218         struct as_parser<char const[N]> : as_parser<char[N]> {};
0219 
0220 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
0221         template <int N>
0222         struct as_parser<wchar_t[N]>
0223         {
0224             typedef literal_string<
0225                 wchar_t const*, char_encoding::standard_wide, unused_type>
0226             type;
0227 
0228             typedef type value_type;
0229 
0230             static constexpr type call(wchar_t const* s)
0231             {
0232                 return type(s);
0233             }
0234         };
0235 
0236         template <int N>
0237         struct as_parser<wchar_t const[N]> : as_parser<wchar_t[N]> {};
0238 #endif
0239 
0240         template <>
0241         struct as_parser<char const*>
0242         {
0243             typedef literal_string<
0244                 char const*, char_encoding::standard, unused_type>
0245             type;
0246 
0247             typedef type value_type;
0248 
0249             static constexpr type call(char const* s)
0250             {
0251                 return type(s);
0252             }
0253         };
0254 
0255         template <typename Char>
0256         struct as_parser< std::basic_string<Char> >
0257         {
0258             typedef literal_string<
0259                 Char const*, char_encoding::standard, unused_type>
0260             type;
0261 
0262             typedef type value_type;
0263 
0264             static type call(std::basic_string<Char> const& s)
0265             {
0266                 return type(s.c_str());
0267             }
0268         };
0269     }
0270 
0271     template <typename String, typename Encoding, typename Attribute>
0272     struct get_info<literal_string<String, Encoding, Attribute>>
0273     {
0274         typedef std::string result_type;
0275         std::string operator()(literal_string<String, Encoding, Attribute> const& p) const
0276         {
0277             return '"' + to_utf8(p.str) + '"';
0278         }
0279     };
0280 }}}
0281 
0282 #endif