From 9f33ff77e8cfaa9280aab47e178d083dd884f8ba Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 25 Jun 2011 22:38:19 +0000 Subject: [PATCH] Added support for some XML entities in add-ons description git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9060 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/addons/addon.cpp | 5 +++++ src/utils/string_utils.cpp | 31 +++++++++++++++++++++++++++++++ src/utils/string_utils.hpp | 8 ++++++++ 3 files changed, 44 insertions(+) diff --git a/src/addons/addon.cpp b/src/addons/addon.cpp index 28758ea16..f637bdb53 100644 --- a/src/addons/addon.cpp +++ b/src/addons/addon.cpp @@ -59,6 +59,11 @@ Addon::Addon(const XMLNode &xml) xml.get("revision", &m_revision ); xml.get("file", &m_zip_file ); xml.get("description", &m_description ); + + // resolve XML entities + m_description = StringUtils::replace(m_description, " ", "\n"); + m_description = StringUtils::replace(m_description, " ", ""); // ignore \r + xml.get("image", &m_icon_url ); // If there is no image, use the icon to display if(m_icon_url=="") diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index 20e81f05c..be989c76e 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -443,6 +443,37 @@ namespace StringUtils return std::string(s); } // timeToString + // ------------------------------------------------------------------------ + + std::string replace(const std::string& other, const std::string& from, const std::string& to) + { + std::string wip = other; + + + while (true) + { + const int pos = wip.find(from); + if (pos == -1) + { + return wip; + } + wip.replace(pos, from.size(), to.c_str(), to.size()); + } + + /* + // found this on google... looks good but doesn't work, it leaves out some occurrences, + // didn't search why + std::string::size_type next; + + for (next = wip.find(from); next != std::string::npos; next = wip.find(from, next)) + { + wip.replace(next, from.length(), to); + next += from.length(); + } + return wip; + */ + } + } // namespace StringUtils /* EOF */ diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index a8fc8d812..c22c62511 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -343,6 +343,14 @@ namespace StringUtils return parseString(input.c_str(), output); } + /** + * \param other string in which to replace stuff + * \param from pattern to remove from the string + * \param to pattern to insert instead + * \return a string with all occurrences of \c from replaced by occurrences of \c to + */ + std::string replace(const std::string& other, const std::string& from, const std::string& to); + } // namespace StringUtils #endif