Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // xml_unescape.hpp Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace iterators { Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // replace &??? xml escape sequences with the corresponding characters Chris@16: template Chris@16: class xml_unescape Chris@16: : public unescape, Base> Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: typedef xml_unescape this_t; Chris@16: typedef unescape super_t; Chris@101: typedef typename boost::iterator_reference reference_type; Chris@16: Chris@16: reference_type dereference() const { Chris@16: return unescape, Base>::dereference(); Chris@16: } Chris@16: public: Chris@16: // workaround msvc 7.1 ICU crash Chris@16: #if defined(BOOST_MSVC) Chris@16: typedef int value_type; Chris@16: #else Chris@101: typedef typename this_t::value_type value_type; Chris@16: #endif Chris@16: Chris@16: void drain_residue(const char *literal); Chris@16: value_type drain(); Chris@16: Chris@16: template Chris@16: xml_unescape(BOOST_PFTO_WRAPPER(T) start) : Chris@16: super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start)))) Chris@16: {} Chris@16: // intel 7.1 doesn't like default copy constructor Chris@16: xml_unescape(const xml_unescape & rhs) : Chris@16: super_t(rhs.base_reference()) Chris@16: {} Chris@16: }; Chris@16: Chris@16: template Chris@16: void xml_unescape::drain_residue(const char * literal){ Chris@16: do{ Chris@16: if(* literal != * ++(this->base_reference())) Chris@16: boost::serialization::throw_exception( Chris@16: dataflow_exception( Chris@16: dataflow_exception::invalid_xml_escape_sequence Chris@16: ) Chris@16: ); Chris@16: } Chris@16: while('\0' != * ++literal); Chris@16: } Chris@16: Chris@16: // note key constraint on this function is that can't "look ahead" any Chris@16: // more than necessary into base iterator. Doing so would alter the base Chris@16: // iterator refenence which would make subsequent iterator comparisons Chris@16: // incorrect and thereby break the composiblity of iterators. Chris@16: template Chris@101: typename xml_unescape::value_type Chris@16: //int Chris@16: xml_unescape::drain(){ Chris@16: value_type retval = * this->base_reference(); Chris@16: if('&' != retval){ Chris@16: return retval; Chris@16: } Chris@16: retval = * ++(this->base_reference()); Chris@16: switch(retval){ Chris@16: case 'l': // < Chris@16: drain_residue("t;"); Chris@16: retval = '<'; Chris@16: break; Chris@16: case 'g': // > Chris@16: drain_residue("t;"); Chris@16: retval = '>'; Chris@16: break; Chris@16: case 'a': Chris@16: retval = * ++(this->base_reference()); Chris@16: switch(retval){ Chris@16: case 'p': // ' Chris@16: drain_residue("os;"); Chris@16: retval = '\''; Chris@16: break; Chris@16: case 'm': // & Chris@16: drain_residue("p;"); Chris@16: retval = '&'; Chris@16: break; Chris@16: } Chris@16: break; Chris@16: case 'q': Chris@16: drain_residue("uot;"); Chris@16: retval = '"'; Chris@16: break; Chris@16: } Chris@16: return retval; Chris@16: } Chris@16: Chris@16: } // namespace iterators Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_ITERATORS_XML_UNESCAPE_HPP