Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / iterators / xml_escape.hpp @ 2486

History | View | Annotate | Download (2.8 kB)

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

    
22
namespace boost { 
23
namespace archive {
24
namespace iterators {
25

    
26
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
27
// insert escapes into xml text
28

    
29
template<class Base>
30
class 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

    
37
public:
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

    
51
template<class Base>
52
char 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
        return current_value;
80
    }
81
    return *bstart;
82
}
83

    
84
template<class Base>
85
wchar_t xml_escape<Base>::fill(
86
    const wchar_t * & bstart, 
87
    const wchar_t * & bend
88
){
89
    wchar_t current_value = * this->base_reference();
90
    switch(current_value){
91
    case '<':
92
        bstart = L"&lt;";
93
        bend = bstart + 4;
94
        break;
95
    case '>':
96
        bstart = L"&gt;";
97
        bend = bstart + 4;
98
        break;
99
    case '&':
100
        bstart = L"&amp;";
101
        bend = bstart + 5;
102
        break;
103
    case '"':
104
        bstart = L"&quot;";
105
        bend = bstart + 6;
106
        break;
107
    case '\'':
108
        bstart = L"&apos;";
109
        bend = bstart + 6;
110
        break;
111
    default:
112
        return current_value;
113
    }
114
    return *bstart;
115
}
116

    
117
} // namespace iterators
118
} // namespace archive
119
} // namespace boost
120

    
121
#endif // BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP