Statistics
| Revision:

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

History | View | Annotate | Download (3.5 kB)

1 2486 sjacqu01
#ifndef BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP
2 2486 sjacqu01
#define BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP
3 2486 sjacqu01
4 2486 sjacqu01
// MS compatible compilers support #pragma once
5 2486 sjacqu01
#if defined(_MSC_VER)
6 2486 sjacqu01
# pragma once
7 2486 sjacqu01
#endif
8 2486 sjacqu01
9 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 2486 sjacqu01
// xml_unescape.hpp
11 2486 sjacqu01
12 2486 sjacqu01
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 2486 sjacqu01
// Use, modification and distribution is subject to the Boost Software
14 2486 sjacqu01
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 2486 sjacqu01
// http://www.boost.org/LICENSE_1_0.txt)
16 2486 sjacqu01
17 2486 sjacqu01
//  See http://www.boost.org for updates, documentation, and revision history.
18 2486 sjacqu01
19 2486 sjacqu01
#include <boost/assert.hpp>
20 2486 sjacqu01
21 2486 sjacqu01
#include <boost/serialization/throw_exception.hpp>
22 2486 sjacqu01
23 2486 sjacqu01
#include <boost/archive/iterators/unescape.hpp>
24 2486 sjacqu01
#include <boost/archive/iterators/dataflow_exception.hpp>
25 2486 sjacqu01
26 2486 sjacqu01
namespace boost {
27 2486 sjacqu01
namespace archive {
28 2486 sjacqu01
namespace iterators {
29 2486 sjacqu01
30 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
31 2486 sjacqu01
// replace &??? xml escape sequences with the corresponding characters
32 2486 sjacqu01
template<class Base>
33 2486 sjacqu01
class xml_unescape
34 2486 sjacqu01
    : public unescape<xml_unescape<Base>, Base>
35 2486 sjacqu01
{
36 2486 sjacqu01
    friend class boost::iterator_core_access;
37 2486 sjacqu01
    typedef xml_unescape<Base> this_t;
38 2486 sjacqu01
    typedef unescape<this_t, Base> super_t;
39 2486 sjacqu01
    typedef typename boost::iterator_reference<this_t> reference_type;
40 2486 sjacqu01
41 2486 sjacqu01
    reference_type dereference() const {
42 2486 sjacqu01
        return unescape<xml_unescape<Base>, Base>::dereference();
43 2486 sjacqu01
    }
44 2486 sjacqu01
public:
45 2486 sjacqu01
    // workaround msvc 7.1 ICU crash
46 2486 sjacqu01
    #if defined(BOOST_MSVC)
47 2486 sjacqu01
        typedef int value_type;
48 2486 sjacqu01
    #else
49 2486 sjacqu01
        typedef typename this_t::value_type value_type;
50 2486 sjacqu01
    #endif
51 2486 sjacqu01
52 2486 sjacqu01
    void drain_residue(const char *literal);
53 2486 sjacqu01
    value_type drain();
54 2486 sjacqu01
55 2486 sjacqu01
    template<class T>
56 2486 sjacqu01
    xml_unescape(T start) :
57 2486 sjacqu01
        super_t(Base(static_cast< T >(start)))
58 2486 sjacqu01
    {}
59 2486 sjacqu01
    // intel 7.1 doesn't like default copy constructor
60 2486 sjacqu01
    xml_unescape(const xml_unescape & rhs) :
61 2486 sjacqu01
        super_t(rhs.base_reference())
62 2486 sjacqu01
    {}
63 2486 sjacqu01
};
64 2486 sjacqu01
65 2486 sjacqu01
template<class Base>
66 2486 sjacqu01
void xml_unescape<Base>::drain_residue(const char * literal){
67 2486 sjacqu01
    do{
68 2486 sjacqu01
        if(* literal != * ++(this->base_reference()))
69 2486 sjacqu01
            boost::serialization::throw_exception(
70 2486 sjacqu01
                dataflow_exception(
71 2486 sjacqu01
                    dataflow_exception::invalid_xml_escape_sequence
72 2486 sjacqu01
                )
73 2486 sjacqu01
            );
74 2486 sjacqu01
    }
75 2486 sjacqu01
    while('\0' != * ++literal);
76 2486 sjacqu01
}
77 2486 sjacqu01
78 2486 sjacqu01
// note key constraint on this function is that can't "look ahead" any
79 2486 sjacqu01
// more than necessary into base iterator.  Doing so would alter the base
80 2486 sjacqu01
// iterator refenence which would make subsequent iterator comparisons
81 2486 sjacqu01
// incorrect and thereby break the composiblity of iterators.
82 2486 sjacqu01
template<class Base>
83 2486 sjacqu01
typename xml_unescape<Base>::value_type
84 2486 sjacqu01
//int
85 2486 sjacqu01
xml_unescape<Base>::drain(){
86 2486 sjacqu01
    value_type retval = * this->base_reference();
87 2486 sjacqu01
    if('&' != retval){
88 2486 sjacqu01
        return retval;
89 2486 sjacqu01
    }
90 2486 sjacqu01
    retval = * ++(this->base_reference());
91 2486 sjacqu01
    switch(retval){
92 2486 sjacqu01
    case 'l': // &lt;
93 2486 sjacqu01
        drain_residue("t;");
94 2486 sjacqu01
        retval = '<';
95 2486 sjacqu01
        break;
96 2486 sjacqu01
    case 'g': // &gt;
97 2486 sjacqu01
        drain_residue("t;");
98 2486 sjacqu01
        retval = '>';
99 2486 sjacqu01
        break;
100 2486 sjacqu01
    case 'a':
101 2486 sjacqu01
        retval = * ++(this->base_reference());
102 2486 sjacqu01
        switch(retval){
103 2486 sjacqu01
        case 'p': // &apos;
104 2486 sjacqu01
            drain_residue("os;");
105 2486 sjacqu01
            retval = '\'';
106 2486 sjacqu01
            break;
107 2486 sjacqu01
        case 'm': // &amp;
108 2486 sjacqu01
            drain_residue("p;");
109 2486 sjacqu01
            retval = '&';
110 2486 sjacqu01
            break;
111 2486 sjacqu01
        }
112 2486 sjacqu01
        break;
113 2486 sjacqu01
    case 'q':
114 2486 sjacqu01
        drain_residue("uot;");
115 2486 sjacqu01
        retval = '"';
116 2486 sjacqu01
        break;
117 2486 sjacqu01
    }
118 2486 sjacqu01
    return retval;
119 2486 sjacqu01
}
120 2486 sjacqu01
121 2486 sjacqu01
} // namespace iterators
122 2486 sjacqu01
} // namespace archive
123 2486 sjacqu01
} // namespace boost
124 2486 sjacqu01
125 2486 sjacqu01
#endif // BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP