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
This commit is contained in:
auria 2011-06-25 22:38:19 +00:00
parent 8bd6a8a4c0
commit 9f33ff77e8
3 changed files with 44 additions and 0 deletions

View File

@ -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=="")

View File

@ -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 */

View File

@ -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