Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/archive/iterators/xml_escape.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // xml_escape.hpp
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 #include <boost/assert.hpp>
0020 #include <boost/archive/iterators/escape.hpp>
0021 
0022 namespace boost {
0023 namespace archive {
0024 namespace iterators {
0025 
0026 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0027 // insert escapes into xml text
0028 
0029 template<class Base>
0030 class xml_escape
0031     : public escape<xml_escape<Base>, Base>
0032 {
0033     friend class boost::iterator_core_access;
0034 
0035     typedef escape<xml_escape<Base>, Base> super_t;
0036 
0037 public:
0038     char fill(const char * & bstart, const char * & bend);
0039     wchar_t fill(const wchar_t * & bstart, const wchar_t * & bend);
0040 
0041     template<class T>
0042     xml_escape(T start) :
0043         super_t(Base(static_cast< T >(start)))
0044     {}
0045     // intel 7.1 doesn't like default copy constructor
0046     xml_escape(const xml_escape & rhs) :
0047         super_t(rhs.base_reference())
0048     {}
0049 };
0050 
0051 template<class Base>
0052 char xml_escape<Base>::fill(
0053     const char * & bstart,
0054     const char * & bend
0055 ){
0056     char current_value = * this->base_reference();
0057     switch(current_value){
0058     case '<':
0059         bstart = "&lt;";
0060         bend = bstart + 4;
0061         break;
0062     case '>':
0063         bstart = "&gt;";
0064         bend = bstart + 4;
0065         break;
0066     case '&':
0067         bstart = "&amp;";
0068         bend = bstart + 5;
0069         break;
0070     case '"':
0071         bstart = "&quot;";
0072         bend = bstart + 6;
0073         break;
0074     case '\'':
0075         bstart = "&apos;";
0076         bend = bstart + 6;
0077         break;
0078     default:
0079         bstart="";
0080         bend=bstart;
0081         return current_value;
0082     }
0083     return *bstart;
0084 }
0085 
0086 template<class Base>
0087 wchar_t xml_escape<Base>::fill(
0088     const wchar_t * & bstart,
0089     const wchar_t * & bend
0090 ){
0091     wchar_t current_value = * this->base_reference();
0092     switch(current_value){
0093     case '<':
0094         bstart = L"&lt;";
0095         bend = bstart + 4;
0096         break;
0097     case '>':
0098         bstart = L"&gt;";
0099         bend = bstart + 4;
0100         break;
0101     case '&':
0102         bstart = L"&amp;";
0103         bend = bstart + 5;
0104         break;
0105     case '"':
0106         bstart = L"&quot;";
0107         bend = bstart + 6;
0108         break;
0109     case '\'':
0110         bstart = L"&apos;";
0111         bend = bstart + 6;
0112         break;
0113     default:
0114         return current_value;
0115     }
0116     return *bstart;
0117 }
0118 
0119 } // namespace iterators
0120 } // namespace archive
0121 } // namespace boost
0122 
0123 #endif // BOOST_ARCHIVE_ITERATORS_XML_ESCAPE_HPP