~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/parser/xml/XmlEscape.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*---------------------------------------------------------------------\
 
2
|                          ____ _   __ __ ___                          |
 
3
|                         |__  / \ / / . \ . \                         |
 
4
|                           / / \ V /|  _/  _/                         |
 
5
|                          / /__ | | | | | |                           |
 
6
|                         /_____||_| |_| |_|                           |
 
7
|                                                                      |
 
8
\---------------------------------------------------------------------*/
 
9
/** \file zypp/parser/xml/XmlEscape.h
 
10
 *
 
11
*/
 
12
#ifndef ZYPP_PARSER_XML_XMLESCAPE_H
 
13
#define ZYPP_PARSER_XML_XMLESCAPE_H
 
14
 
 
15
#include <sstream>
 
16
#include <string>
 
17
#include "zypp/APIConfig.h"
 
18
 
 
19
///////////////////////////////////////////////////////////////////
 
20
namespace zypp
 
21
{
 
22
  ///////////////////////////////////////////////////////////////////
 
23
  namespace xml
 
24
  {
 
25
    ///////////////////////////////////////////////////////////////////
 
26
    namespace detail
 
27
    {
 
28
      struct EscapedString
 
29
      {
 
30
        EscapedString( const std::string & in_r ) : _in( in_r ) {}
 
31
        std::ostream & dumpOn( std::ostream & str ) const;
 
32
        operator std::string() const
 
33
        { std::ostringstream str; dumpOn( str ); return str.str(); }
 
34
      private:
 
35
        const std::string & _in;
 
36
      };
 
37
 
 
38
      /** \relates EscapedString Stream output */
 
39
      inline std::ostream & operator<<( std::ostream & str, const EscapedString & obj )
 
40
      { return obj.dumpOn( str ); }
 
41
 
 
42
    } // detail
 
43
    ///////////////////////////////////////////////////////////////////
 
44
 
 
45
    /** Escape xml special charaters (<tt>& -> &amp;</tt>; from IoBind library).
 
46
     * The \ref detail::EscapedString can be dumped to an ostream and implicitly
 
47
     * converts into a std::string.
 
48
     */
 
49
    inline detail::EscapedString escape( const std::string & in_r )
 
50
    { return detail::EscapedString( in_r ); }
 
51
 
 
52
    /** Unescape xml special charaters (<tt>&amp; -> &</tt>; from IoBind library) */
 
53
    ZYPP_API std::string unescape( const std::string & in_r );
 
54
 
 
55
  } // namespace xml
 
56
  /////////////////////////////////////////////////////////////////
 
57
} // namespace zypp
 
58
///////////////////////////////////////////////////////////////////
 
59
#endif // ZYPP_PARSER_XML_XMLESCAPE_H