Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:36

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 // 
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #if !defined(BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM)
0007 #define BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/support/char_class.hpp>
0014 #include <boost/spirit/home/karma/detail/generate_to.hpp>
0015 #include <boost/range/begin.hpp>
0016 #include <boost/range/end.hpp>
0017 
0018 namespace boost { namespace spirit { namespace karma { namespace detail
0019 {
0020     ///////////////////////////////////////////////////////////////////////////
0021     // pass through character transformation
0022     struct pass_through_filter
0023     {
0024         template <typename Char>
0025         Char operator()(Char ch) const
0026         {
0027             return ch;
0028         }
0029     };
0030 
0031     template <typename CharEncoding, typename Tag>
0032     struct encoding_filter
0033     {
0034         template <typename Char>
0035         Char operator()(Char ch) const
0036         {
0037             return spirit::char_class::convert<CharEncoding>::to(Tag(), ch);
0038         }
0039     };
0040 
0041     ///////////////////////////////////////////////////////////////////////////
0042     //  generate a string given by a std::string, applying the given filter
0043     template <typename OutputIterator, typename Char, typename Filter>
0044     inline bool string_generate(OutputIterator& sink, Char const* str
0045       , Filter filter)
0046     {
0047         for (Char ch = *str; ch != 0; ch = *++str)
0048         {
0049             *sink = filter(ch);
0050             ++sink;
0051         }
0052         return detail::sink_is_good(sink);
0053     }
0054 
0055     template <typename OutputIterator, typename Container, typename Filter>
0056     inline bool string_generate(OutputIterator& sink
0057       , Container const& c, Filter filter)
0058     {
0059         typedef typename traits::container_iterator<Container const>::type 
0060             iterator;
0061 
0062         const iterator end = boost::end(c);
0063         for (iterator it = boost::begin(c); it != end; ++it)
0064         {
0065             *sink = filter(*it);
0066             ++sink;
0067         }
0068         return detail::sink_is_good(sink);
0069     }
0070 
0071     ///////////////////////////////////////////////////////////////////////////
0072     //  generate a string without any transformation
0073     template <typename OutputIterator, typename Char>
0074     inline bool string_generate(OutputIterator& sink, Char const* str)
0075     {
0076         return string_generate(sink, str, pass_through_filter());
0077     }
0078 
0079     template <typename OutputIterator, typename Container>
0080     inline bool string_generate(OutputIterator& sink
0081       , Container const& c)
0082     {
0083         return string_generate(sink, c, pass_through_filter());
0084     }
0085 
0086     ///////////////////////////////////////////////////////////////////////////
0087     //  generate a string given by a pointer, converting according using a 
0088     //  given character class and case tag
0089     template <typename OutputIterator, typename Char, typename CharEncoding
0090       , typename Tag>
0091     inline bool string_generate(OutputIterator& sink
0092       , Char const* str
0093       , CharEncoding, Tag)
0094     {
0095         return string_generate(sink, str, encoding_filter<CharEncoding, Tag>());
0096     }
0097 
0098     template <typename OutputIterator, typename Container
0099       , typename CharEncoding, typename Tag>
0100     inline bool 
0101     string_generate(OutputIterator& sink
0102       , Container const& c
0103       , CharEncoding, Tag)
0104     {
0105         return string_generate(sink, c, encoding_filter<CharEncoding, Tag>());
0106     }
0107 
0108     ///////////////////////////////////////////////////////////////////////////
0109     template <typename OutputIterator, typename Char>
0110     inline bool string_generate(OutputIterator& sink
0111       , Char const* str
0112       , unused_type, unused_type)
0113     {
0114         return string_generate(sink, str);
0115     }
0116 
0117     template <typename OutputIterator, typename Container>
0118     inline bool string_generate(OutputIterator& sink
0119       , Container const& c
0120       , unused_type, unused_type)
0121     {
0122         return string_generate(sink, c);
0123     }
0124 
0125 }}}}
0126 
0127 #endif