2
* Copyright Andrey Semashev 2007 - 2013.
3
* Distributed under the Boost Software License, Version 1.0.
4
* (See accompanying file LICENSE_1_0.txt or copy at
5
* http://www.boost.org/LICENSE_1_0.txt)
8
* \file formatters/xml_decorator.hpp
9
* \author Andrey Semashev
12
* The header contains implementation of a XML-style character decorator.
15
#ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_
16
#define BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_
18
#include <boost/range/iterator_range_core.hpp>
19
#include <boost/log/detail/config.hpp>
20
#include <boost/log/expressions/formatters/char_decorator.hpp>
21
#include <boost/log/detail/header.hpp>
23
#ifdef BOOST_LOG_HAS_PRAGMA_ONCE
29
BOOST_LOG_OPEN_NAMESPACE
31
namespace expressions {
36
struct xml_decorator_traits;
38
#ifdef BOOST_LOG_USE_CHAR
40
struct xml_decorator_traits< char >
42
static boost::iterator_range< const char* const* > get_patterns()
44
static const char* const patterns[] =
48
return boost::make_iterator_range(patterns);
50
static boost::iterator_range< const char* const* > get_replacements()
52
static const char* const replacements[] =
54
"&", "<", ">", "'"
56
return boost::make_iterator_range(replacements);
59
#endif // BOOST_LOG_USE_CHAR
61
#ifdef BOOST_LOG_USE_WCHAR_T
63
struct xml_decorator_traits< wchar_t >
65
static boost::iterator_range< const wchar_t* const* > get_patterns()
67
static const wchar_t* const patterns[] =
69
L"&", L"<", L">", L"'"
71
return boost::make_iterator_range(patterns);
73
static boost::iterator_range< const wchar_t* const* > get_replacements()
75
static const wchar_t* const replacements[] =
77
L"&", L"<", L">", L"'"
79
return boost::make_iterator_range(replacements);
82
#endif // BOOST_LOG_USE_WCHAR_T
84
template< typename CharT >
85
struct xml_decorator_gen
87
typedef CharT char_type;
89
template< typename SubactorT >
90
BOOST_LOG_FORCEINLINE char_decorator_actor< SubactorT, pattern_replacer< char_type > > operator[] (SubactorT const& subactor) const
92
typedef xml_decorator_traits< char_type > traits_type;
93
typedef pattern_replacer< char_type > replacer_type;
94
typedef char_decorator_actor< SubactorT, replacer_type > result_type;
95
typedef typename result_type::terminal_type terminal_type;
96
typename result_type::base_type act = {{ terminal_type(subactor, replacer_type(traits_type::get_patterns(), traits_type::get_replacements())) }};
97
return result_type(act);
104
* XML-style decorator generator object. The decorator replaces characters that have special meaning
105
* in XML documents with the corresponding decorated counterparts. The generator provides
106
* <tt>operator[]</tt> that can be used to construct the actual decorator. For example:
109
* xml_decor[ attr< std::string >("MyAttr") ]
112
* For wide-character formatting there is the similar \c wxml_decor decorator generator object.
114
#ifdef BOOST_LOG_USE_CHAR
115
const aux::xml_decorator_gen< char > xml_decor = {};
117
#ifdef BOOST_LOG_USE_WCHAR_T
118
const aux::xml_decorator_gen< wchar_t > wxml_decor = {};
122
* The function creates an XML-style decorator generator for arbitrary character type.
124
template< typename CharT >
125
BOOST_LOG_FORCEINLINE aux::xml_decorator_gen< CharT > make_xml_decor()
127
return aux::xml_decorator_gen< CharT >();
130
} // namespace expressions
132
BOOST_LOG_CLOSE_NAMESPACE // namespace log
136
#include <boost/log/detail/footer.hpp>
138
#endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_