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) && (_MSC_VER >= 1020)
|
---|
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 <cassert>
|
---|
20 |
|
---|
21 | #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
|
---|
22 | #include <boost/pfto.hpp>
|
---|
23 |
|
---|
24 | #include <boost/archive/iterators/escape.hpp>
|
---|
25 |
|
---|
26 | namespace boost {
|
---|
27 | namespace archive {
|
---|
28 | namespace iterators {
|
---|
29 |
|
---|
30 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
31 | // insert escapes into xml text
|
---|
32 |
|
---|
33 | template<class Base>
|
---|
34 | class xml_escape
|
---|
35 | : public escape<xml_escape<Base>, Base>
|
---|
36 | {
|
---|
37 | friend class boost::iterator_core_access;
|
---|
38 |
|
---|
39 | typedef escape<xml_escape<Base>, Base> super_t;
|
---|
40 |
|
---|
41 | public:
|
---|
42 | char fill(const char * & bstart, const char * & bend);
|
---|
43 | wchar_t fill(const wchar_t * & bstart, const wchar_t * & bend);
|
---|
44 |
|
---|
45 | template<class T>
|
---|
46 | xml_escape(BOOST_PFTO_WRAPPER(T) start) :
|
---|
47 | super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast<T>(start))))
|
---|
48 | {}
|
---|
49 | // intel 7.1 doesn't like default copy constructor
|
---|
50 | xml_escape(const xml_escape & rhs) :
|
---|
51 | super_t(rhs.base_reference())
|
---|
52 | {}
|
---|
53 | };
|
---|
54 |
|
---|
55 | template<class Base>
|
---|
56 | char xml_escape<Base>::fill(
|
---|
57 | const char * & bstart,
|
---|
58 | const char * & bend
|
---|
59 | ){
|
---|
60 | char current_value = * this->base_reference();
|
---|
61 | switch(current_value){
|
---|
62 | case '<':
|
---|
63 | bstart = "<";
|
---|
64 | bend = bstart + 4;
|
---|
65 | break;
|
---|
66 | case '>':
|
---|
67 | bstart = ">";
|
---|
68 | bend = bstart + 4;
|
---|
69 | break;
|
---|
70 | case '&':
|
---|
71 | bstart = "&";
|
---|
72 | bend = bstart + 5;
|
---|
73 | break;
|
---|
74 | case '"':
|
---|
75 | bstart = """;
|
---|
76 | bend = bstart + 6;
|
---|
77 | break;
|
---|
78 | case '\'':
|
---|
79 | bstart = "'";
|
---|
80 | bend = bstart + 6;
|
---|
81 | break;
|
---|
82 | default:
|
---|
83 | return current_value;
|
---|
84 | }
|
---|
85 | return *bstart;
|
---|
86 | }
|
---|
87 |
|
---|
88 | template<class Base>
|
---|
89 | wchar_t xml_escape<Base>::fill(
|
---|
90 | const wchar_t * & bstart,
|
---|
91 | const wchar_t * & bend
|
---|
92 | ){
|
---|
93 | wchar_t current_value = * this->base_reference();
|
---|
94 | switch(current_value){
|
---|
95 | case '<':
|
---|
96 | bstart = L"<";
|
---|
97 | bend = bstart + 4;
|
---|
98 | break;
|
---|
99 | case '>':
|
---|
100 | bstart = L">";
|
---|
101 | bend = bstart + 4;
|
---|
102 | break;
|
---|
103 | case '&':
|
---|
104 | bstart = L"&";
|
---|
105 | bend = bstart + 5;
|
---|
106 | break;
|
---|
107 | case '"':
|
---|
108 | bstart = L""";
|
---|
109 | bend = bstart + 6;
|
---|
110 | break;
|
---|
111 | case '\'':
|
---|
112 | bstart = L"'";
|
---|
113 | bend = bstart + 6;
|
---|
114 | break;
|
---|
115 | default:
|
---|
116 | return current_value;
|
---|
117 | }
|
---|
118 | return *bstart;
|
---|
119 | }
|
---|
120 |
|
---|
121 | } // namespace iterators
|
---|
122 | } // namespace archive
|
---|
123 | } // namespace boost
|
---|
124 |
|
---|
125 | #endif // BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
|
---|