source: NonGTP/Boost/boost/archive/iterators/xml_escape.hpp @ 857

Revision 857, 3.1 KB checked in by igarcia, 18 years ago (diff)
Line 
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
26namespace boost {
27namespace archive {
28namespace iterators {
29
30/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
31// insert escapes into xml text
32
33template<class Base>
34class 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
41public:
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
55template<class Base>
56char 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 = "&lt;";
64        bend = bstart + 4;
65        break;
66    case '>':
67        bstart = "&gt;";
68        bend = bstart + 4;
69        break;
70    case '&':
71        bstart = "&amp;";
72        bend = bstart + 5;
73        break;
74    case '"':
75        bstart = "&quot;";
76        bend = bstart + 6;
77        break;
78    case '\'':
79        bstart = "&apos;";
80        bend = bstart + 6;
81        break;
82    default:
83        return current_value;
84    }
85    return *bstart;
86}
87
88template<class Base>
89wchar_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"&lt;";
97        bend = bstart + 4;
98        break;
99    case '>':
100        bstart = L"&gt;";
101        bend = bstart + 4;
102        break;
103    case '&':
104        bstart = L"&amp;";
105        bend = bstart + 5;
106        break;
107    case '"':
108        bstart = L"&quot;";
109        bend = bstart + 6;
110        break;
111    case '\'':
112        bstart = L"&apos;";
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
Note: See TracBrowser for help on using the repository browser.