1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #if !defined(BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM)
7 #define BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM
14 #include <boost/spirit/home/support/char_class.hpp>
15 #include <boost/spirit/home/karma/detail/generate_to.hpp>
16 #include <boost/range/const_iterator.hpp>
18 namespace boost { namespace spirit { namespace karma { namespace detail
20 ///////////////////////////////////////////////////////////////////////////
21 // pass through character transformation
22 struct pass_through_filter
24 template <typename Char>
25 Char operator()(Char ch) const
31 template <typename CharEncoding, typename Tag>
32 struct encoding_filter
34 template <typename Char>
35 Char operator()(Char ch) const
37 return spirit::char_class::convert<CharEncoding>::to(Tag(), ch);
41 ///////////////////////////////////////////////////////////////////////////
42 // generate a string given by a std::string, applying the given filter
43 template <typename OutputIterator, typename Char, typename Filter>
44 inline bool string_generate(OutputIterator& sink, Char const* str
47 for (Char ch = *str; ch != 0; ch = *++str)
52 return detail::sink_is_good(sink);
55 template <typename OutputIterator, typename Container, typename Filter>
56 inline bool string_generate(OutputIterator& sink
57 , Container const& c, Filter filter)
59 typedef typename traits::container_iterator<Container const>::type
62 const iterator end = boost::end(c);
63 for (iterator it = boost::begin(c); it != end; ++it)
68 return detail::sink_is_good(sink);
71 ///////////////////////////////////////////////////////////////////////////
72 // generate a string without any transformation
73 template <typename OutputIterator, typename Char>
74 inline bool string_generate(OutputIterator& sink, Char const* str)
76 return string_generate(sink, str, pass_through_filter());
79 template <typename OutputIterator, typename Container>
80 inline bool string_generate(OutputIterator& sink
83 return string_generate(sink, c, pass_through_filter());
86 ///////////////////////////////////////////////////////////////////////////
87 // generate a string given by a pointer, converting according using a
88 // given character class and case tag
89 template <typename OutputIterator, typename Char, typename CharEncoding
91 inline bool string_generate(OutputIterator& sink
95 return string_generate(sink, str, encoding_filter<CharEncoding, Tag>());
98 template <typename OutputIterator, typename Container
99 , typename CharEncoding, typename Tag>
101 string_generate(OutputIterator& sink
105 return string_generate(sink, c, encoding_filter<CharEncoding, Tag>());
108 ///////////////////////////////////////////////////////////////////////////
109 template <typename OutputIterator, typename Char>
110 inline bool string_generate(OutputIterator& sink
112 , unused_type, unused_type)
114 return string_generate(sink, str);
117 template <typename OutputIterator, typename Container>
118 inline bool string_generate(OutputIterator& sink
120 , unused_type, unused_type)
122 return string_generate(sink, c);