Author: matz
Date: Mon Feb 11 05:30:08 2008
New Revision: 8600
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8600&view=rev
Log:
Dear Lord! There's always infinite amazement into which total and utter
crap code can transform by using boost. This removes 325 lines, adds
47 new ones (for a slow implementation of XML escaping) and now my
"zypper in kde4-bozo" takes 14 seconds instead of 128. Yes, nine times
faster! There should be a severe penalty for using boost for ANYTHING.
Removed:
branches/tmp/ma/jump_sat/libzypp/zypp/parser/parser_utils.hpp
Modified:
branches/tmp/ma/jump_sat/libzypp/zypp/parser/xml_escape_parser.cpp
Modified: branches/tmp/ma/jump_sat/libzypp/zypp/parser/xml_escape_parser.cpp
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/libzypp/zypp/parser/xml_escape_parser.cpp?rev=8600&r1=8599&r2=8600&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/libzypp/zypp/parser/xml_escape_parser.cpp (original)
+++ branches/tmp/ma/jump_sat/libzypp/zypp/parser/xml_escape_parser.cpp Mon Feb 11 05:30:08 2008
@@ -1,149 +1,64 @@
-/*
-IoBind Library License:
---------------------------
-
-The zlib/libpng License Copyright (c) 2003 Jonathan de Halleux
-
-This 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.
-
-Permission 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:
-
-1. 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.
-
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source distribution
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/xml_escape_parser.cpp
+ *
*/
-
#include <string>
-#include <sstream>
-#include
-#include
-#include "parser_utils.hpp"
#include "xml_escape_parser.hpp"
-
namespace iobind{
namespace parser{
-namespace detail{
-struct escapes : boost::spirit::symbolsstd::string
+std::string xml_escape_parser::escape(const std::string &istr) const
{
- escapes()
+ size_t i;
+ std::string str = istr;
+ i = str.find_first_of("<>&'\"");
+ while (i != std::string::npos)
{
- add
- ("<" , "lt")
- (">" , "gt")
- ("&" , "amp")
- ("'" , "apos")
- ("\"" , "quot")
- ;
+ switch (str[i])
+ {
+ case '<': str.replace(i, 1, "<"); i += 3; break;
+ case '>': str.replace(i, 1, ">"); i += 3; break;
+ case '&': str.replace(i, 1, "&"); i += 4; break;
+ case '\'': str.replace(i, 1, "'"); i += 5; break;
+ case '"': str.replace(i, 1, """); i += 5; break;
+ }
+ i = str.find_first_of("<>&'\"", i + 1);
}
+ return str;
+}
-} escapes_p;
-
-struct unescapes : boost::spirit::symbolsstd::string
+std::string xml_escape_parser::unescape(const std::string &istr) const
{
- unescapes()
+ size_t i;
+ std::string str = istr;
+ i = str.find_first_of("&");
+ while (i != std::string::npos)
{
- add
- ("lt", "<")
- ("gt",">")
- ("amp","&")
- ("apos","\'")
- ("quot","\"")
- ;
+ if (str[i] == '&')
+ {
+ if (!str.compare(i + 1, 3, "lt;"))
+ str.replace(i, 4, 1, '<');
+ else if (!str.compare(i + 1, 3, "gt;"))
+ str.replace(i, 4, 1, '>');
+ else if (!str.compare(i + 1, 4, "amp;"))
+ str.replace(i, 5, 1, '&');
+ else if (!str.compare(i + 1, 5, "apos;"))
+ str.replace(i, 6, 1, '\'');
+ else if (!str.compare(i + 1, 5, "quot;"))
+ str.replace(i, 6, 1, '"');
+ }
+ i = str.find_first_of("&", i + 1);
}
-} unescapes_p;
-
-struct unescape_from_xml_grammar : boost::spirit::grammar
-{
- std::ostream& out;
-
- explicit unescape_from_xml_grammar( std::ostream& out_)
- :out(out_){};
-
- template <typename ScannerT>
- struct definition
- {
- definition(unescape_from_xml_grammar const& self)
- {
- using namespace boost::spirit;
-
- begin = ch_p('&');
- end = ch_p(';');
- // the rest is ok
- encoded_string=
- *(
- begin >> unescapes_p[concat_symbol(self.out)] >> end
- | anychar_p[concat_string(self.out)]
- );
- };
-
- boost::spirit::rule<ScannerT> encoded_string, begin, end;
- boost::spirit::rule<ScannerT> const& start() const { return encoded_string; };
- };
-};
-
-struct escape_to_xml_grammar : boost::spirit::grammar
-{
- std::ostream& out;
-
- explicit escape_to_xml_grammar( std::ostream& out_)
- :out(out_){};
-
- template <typename ScannerT>
- struct definition
- {
- definition(escape_to_xml_grammar const& self)
- {
- using namespace boost::spirit;
- concat_pre_post_symbol concatener(self.out, "&", ";");
-
- // the rest is ok
- encoded_string=
- *(
- escapes_p[concatener]
- | anychar_p[concat_string(self.out)]
- );
- };
-
- boost::spirit::rule<ScannerT> encoded_string;
- boost::spirit::rule<ScannerT> const& start() const { return encoded_string; };
- };
-};
-
-}; //details
-
-
-std::string xml_escape_parser::escape( std::string const& str) const
-{
- using namespace boost::spirit;
-
- std::ostringstream out;
-
- parse_info<> info = boost::spirit::parse(
- str.c_str(),
- detail::escape_to_xml_grammar(out)
- );
-
- return out.str();
-};
-
-std::string xml_escape_parser::unescape( std::string const& str) const
-{
- using namespace boost::spirit;
-
- std::ostringstream out;
-
- parse_info<> info = boost::spirit::parse(
- str.c_str(),
- detail::unescape_from_xml_grammar(out)
- );
-
- return out.str();
-};
+ return str;
+}
}; // parser
}; // iobind
-
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org