1#ifndef BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
2#define BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER)
6# pragma once
7#endif
8
9/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10// xml_escape.hpp
11
12// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13// Use, modification and distribution is subject to the Boost Software
14// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15// http://www.boost.org/LICENSE_1_0.txt)
16
17// See http://www.boost.org for updates, documentation, and revision history.
18
19#include <boost/assert.hpp>
20#include <boost/archive/iterators/escape.hpp>
21
22namespace boost {
23namespace archive {
24namespace iterators {
25
26/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
27// insert escapes into xml text
28
29template<class Base>
30class xml_escape
31 : public escape<xml_escape<Base>, Base>
32{
33 friend class boost::iterator_core_access;
34
35 typedef escape<xml_escape<Base>, Base> super_t;
36
37public:
38 char fill(const char * & bstart, const char * & bend);
39 wchar_t fill(const wchar_t * & bstart, const wchar_t * & bend);
40
41 template<class T>
42 xml_escape(T start) :
43 super_t(Base(static_cast< T >(start)))
44 {}
45 // intel 7.1 doesn't like default copy constructor
46 xml_escape(const xml_escape & rhs) :
47 super_t(rhs.base_reference())
48 {}
49};
50
51template<class Base>
52char xml_escape<Base>::fill(
53 const char * & bstart,
54 const char * & bend
55){
56 char current_value = * this->base_reference();
57 switch(current_value){
58 case '<':
59 bstart = "&lt;";
60 bend = bstart + 4;
61 break;
62 case '>':
63 bstart = "&gt;";
64 bend = bstart + 4;
65 break;
66 case '&':
67 bstart = "&amp;";
68 bend = bstart + 5;
69 break;
70 case '"':
71 bstart = "&quot;";
72 bend = bstart + 6;
73 break;
74 case '\'':
75 bstart = "&apos;";
76 bend = bstart + 6;
77 break;
78 default:
79 bstart="";
80 bend=bstart;
81 return current_value;
82 }
83 return *bstart;
84}
85
86template<class Base>
87wchar_t xml_escape<Base>::fill(
88 const wchar_t * & bstart,
89 const wchar_t * & bend
90){
91 wchar_t current_value = * this->base_reference();
92 switch(current_value){
93 case '<':
94 bstart = L"&lt;";
95 bend = bstart + 4;
96 break;
97 case '>':
98 bstart = L"&gt;";
99 bend = bstart + 4;
100 break;
101 case '&':
102 bstart = L"&amp;";
103 bend = bstart + 5;
104 break;
105 case '"':
106 bstart = L"&quot;";
107 bend = bstart + 6;
108 break;
109 case '\'':
110 bstart = L"&apos;";
111 bend = bstart + 6;
112 break;
113 default:
114 return current_value;
115 }
116 return *bstart;
117}
118
119} // namespace iterators
120} // namespace archive
121} // namespace boost
122
123#endif // BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
124

source code of boost/libs/serialization/include/boost/archive/iterators/xml_escape.hpp