annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/detail/string_generate.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 2 //
Chris@16 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 #if !defined(BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM)
Chris@16 7 #define BOOST_SPIRIT_KARMA_STRING_GENERATE_FEB_23_2007_1232PM
Chris@16 8
Chris@16 9 #if defined(_MSC_VER)
Chris@16 10 #pragma once
Chris@16 11 #endif
Chris@16 12
Chris@16 13 #include <string>
Chris@16 14 #include <boost/spirit/home/support/char_class.hpp>
Chris@16 15 #include <boost/spirit/home/karma/detail/generate_to.hpp>
Chris@16 16 #include <boost/range/const_iterator.hpp>
Chris@16 17
Chris@16 18 namespace boost { namespace spirit { namespace karma { namespace detail
Chris@16 19 {
Chris@16 20 ///////////////////////////////////////////////////////////////////////////
Chris@16 21 // pass through character transformation
Chris@16 22 struct pass_through_filter
Chris@16 23 {
Chris@16 24 template <typename Char>
Chris@16 25 Char operator()(Char ch) const
Chris@16 26 {
Chris@16 27 return ch;
Chris@16 28 }
Chris@16 29 };
Chris@16 30
Chris@16 31 template <typename CharEncoding, typename Tag>
Chris@16 32 struct encoding_filter
Chris@16 33 {
Chris@16 34 template <typename Char>
Chris@16 35 Char operator()(Char ch) const
Chris@16 36 {
Chris@16 37 return spirit::char_class::convert<CharEncoding>::to(Tag(), ch);
Chris@16 38 }
Chris@16 39 };
Chris@16 40
Chris@16 41 ///////////////////////////////////////////////////////////////////////////
Chris@16 42 // generate a string given by a std::string, applying the given filter
Chris@16 43 template <typename OutputIterator, typename Char, typename Filter>
Chris@16 44 inline bool string_generate(OutputIterator& sink, Char const* str
Chris@16 45 , Filter filter)
Chris@16 46 {
Chris@16 47 for (Char ch = *str; ch != 0; ch = *++str)
Chris@16 48 {
Chris@16 49 *sink = filter(ch);
Chris@16 50 ++sink;
Chris@16 51 }
Chris@16 52 return detail::sink_is_good(sink);
Chris@16 53 }
Chris@16 54
Chris@16 55 template <typename OutputIterator, typename Container, typename Filter>
Chris@16 56 inline bool string_generate(OutputIterator& sink
Chris@16 57 , Container const& c, Filter filter)
Chris@16 58 {
Chris@16 59 typedef typename traits::container_iterator<Container const>::type
Chris@16 60 iterator;
Chris@16 61
Chris@16 62 iterator end = boost::end(c);
Chris@16 63 for (iterator it = boost::begin(c); it != end; ++it)
Chris@16 64 {
Chris@16 65 *sink = filter(*it);
Chris@16 66 ++sink;
Chris@16 67 }
Chris@16 68 return detail::sink_is_good(sink);
Chris@16 69 }
Chris@16 70
Chris@16 71 ///////////////////////////////////////////////////////////////////////////
Chris@16 72 // generate a string without any transformation
Chris@16 73 template <typename OutputIterator, typename Char>
Chris@16 74 inline bool string_generate(OutputIterator& sink, Char const* str)
Chris@16 75 {
Chris@16 76 return string_generate(sink, str, pass_through_filter());
Chris@16 77 }
Chris@16 78
Chris@16 79 template <typename OutputIterator, typename Char, typename Traits
Chris@16 80 , typename Allocator>
Chris@16 81 inline bool string_generate(OutputIterator& sink
Chris@16 82 , std::basic_string<Char, Traits, Allocator> const& str)
Chris@16 83 {
Chris@16 84 return string_generate(sink, str.c_str(), pass_through_filter());
Chris@16 85 }
Chris@16 86
Chris@16 87 template <typename OutputIterator, typename Container>
Chris@16 88 inline bool string_generate(OutputIterator& sink
Chris@16 89 , Container const& c)
Chris@16 90 {
Chris@16 91 return string_generate(sink, c, pass_through_filter());
Chris@16 92 }
Chris@16 93
Chris@16 94 ///////////////////////////////////////////////////////////////////////////
Chris@16 95 // generate a string given by a pointer, converting according using a
Chris@16 96 // given character class and case tag
Chris@16 97 template <typename OutputIterator, typename Char, typename CharEncoding
Chris@16 98 , typename Tag>
Chris@16 99 inline bool string_generate(OutputIterator& sink
Chris@16 100 , Char const* str
Chris@16 101 , CharEncoding, Tag)
Chris@16 102 {
Chris@16 103 return string_generate(sink, str, encoding_filter<CharEncoding, Tag>());
Chris@16 104 }
Chris@16 105
Chris@16 106 template <typename OutputIterator, typename Char
Chris@16 107 , typename CharEncoding, typename Tag
Chris@16 108 , typename Traits, typename Allocator>
Chris@16 109 inline bool string_generate(OutputIterator& sink
Chris@16 110 , std::basic_string<Char, Traits, Allocator> const& str
Chris@16 111 , CharEncoding, Tag)
Chris@16 112 {
Chris@16 113 return string_generate(sink, str.c_str()
Chris@16 114 , encoding_filter<CharEncoding, Tag>());
Chris@16 115 }
Chris@16 116
Chris@16 117 template <typename OutputIterator, typename Container
Chris@16 118 , typename CharEncoding, typename Tag>
Chris@16 119 inline bool
Chris@16 120 string_generate(OutputIterator& sink
Chris@16 121 , Container const& c
Chris@16 122 , CharEncoding, Tag)
Chris@16 123 {
Chris@16 124 return string_generate(sink, c, encoding_filter<CharEncoding, Tag>());
Chris@16 125 }
Chris@16 126
Chris@16 127 ///////////////////////////////////////////////////////////////////////////
Chris@16 128 template <typename OutputIterator, typename Char>
Chris@16 129 inline bool string_generate(OutputIterator& sink
Chris@16 130 , Char const* str
Chris@16 131 , unused_type, unused_type)
Chris@16 132 {
Chris@16 133 return string_generate(sink, str, pass_through_filter());
Chris@16 134 }
Chris@16 135
Chris@16 136 template <typename OutputIterator, typename Char, typename Traits
Chris@16 137 , typename Allocator>
Chris@16 138 inline bool string_generate(OutputIterator& sink
Chris@16 139 , std::basic_string<Char, Traits, Allocator> const& str
Chris@16 140 , unused_type, unused_type)
Chris@16 141 {
Chris@16 142 return string_generate(sink, str.c_str(), pass_through_filter());
Chris@16 143 }
Chris@16 144
Chris@16 145 template <typename OutputIterator, typename Container>
Chris@16 146 inline bool string_generate(OutputIterator& sink
Chris@16 147 , Container const& c
Chris@16 148 , unused_type, unused_type)
Chris@16 149 {
Chris@16 150 return string_generate(sink, c, pass_through_filter());
Chris@16 151 }
Chris@16 152
Chris@16 153 }}}}
Chris@16 154
Chris@16 155 #endif