libzypp 17.31.23
XmlEscape.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include <string>
14#include <zypp-core/parser/xml/XmlEscape.h>
15
16/*
17IoBind Library License:
18--------------------------
19
20The zlib/libpng License Copyright (c) 2003 Jonathan de Halleux
21
22This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
23
24Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
25
261. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
27
282. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
29
303. This notice may not be removed or altered from any source distribution
31*/
33namespace iobind
34{
36 namespace parser
37 {
39 {
40 std::string unescape(const std::string &istr) const
41 {
42 size_t i;
43 std::string str = istr;
44 i = str.find_first_of("&");
45 while (i != std::string::npos)
46 {
47 if (str[i] == '&')
48 {
49 if (!str.compare(i + 1, 3, "lt;"))
50 str.replace(i, 4, 1, '<');
51 else if (!str.compare(i + 1, 3, "gt;"))
52 str.replace(i, 4, 1, '>');
53 else if (!str.compare(i + 1, 4, "amp;"))
54 str.replace(i, 5, 1, '&');
55 else if (!str.compare(i + 1, 5, "apos;"))
56 str.replace(i, 6, 1, '\'');
57 else if (!str.compare(i + 1, 5, "quot;"))
58 str.replace(i, 6, 1, '"');
59 }
60 i = str.find_first_of("&", i + 1);
61 }
62 return str;
63 }
64 };
65 } // namespace parser
67} // namespace iobind
69
71namespace zypp
72{
74 namespace xml
75 {
77 namespace detail
78 {
79 std::ostream & EscapedString::dumpOn( std::ostream & str ) const
80 {
81 typedef unsigned char uchar;
82 for ( char ch : _in )
83 {
84 switch ( ch )
85 {
86 case '<': str << "&lt;"; break;
87 case '>': str << "&gt;"; break;
88 case '&': str << "&amp;"; break;
89 case '"': str << "&quot;"; break;
90 case '\'': str << "&apos;"; break;
91
92 // control chars we allow:
93 case '\n':
94 case '\r':
95 case '\t':
96 str << ch;
97 break;
98
99 default:
100 if ( uchar(ch) < 32u )
101 str << '?'; // filter problematic control chars (XML1.0)
102 else
103 str << ch;
104 break;
105 }
106 }
107 return str;
108 }
109
110 } // detail
112
113 std::string unescape( const std::string & in_r )
114 { return iobind::parser::xml_escape_parser().unescape( in_r ); }
115
116 } // namespace xml
118} // namespace zypp
String related utilities and Regular expression matching.
std::string unescape(const std::string &in_r)
Unescape xml special charaters (& -> &; from IoBind library)
Definition: XmlEscape.cc:113
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::string unescape(const std::string &istr) const
Definition: XmlEscape.cc:40
std::ostream & dumpOn(std::ostream &str) const
Definition: XmlEscape.cc:79
const std::string & _in
Definition: XmlEscape.h:37
#define ZYPP_LOCAL
Definition: Globals.h:59