move encodeAttribute from Property to Persitence to avoid code duplication

This commit is contained in:
wmayer
2017-11-26 18:38:45 +01:00
parent fcb5b9cde1
commit 2059d47e2c
7 changed files with 30 additions and 57 deletions

View File

@@ -304,31 +304,6 @@ std::string DynamicProperty::getUniquePropertyName(const char *Name) const
}
}
std::string DynamicProperty::encodeAttribute(const std::string& str) const
{
std::string tmp;
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
if (*it == '<')
tmp += "&lt;";
else if (*it == '"')
tmp += "&quot;";
else if (*it == '\'')
tmp += "&apos;";
else if (*it == '&')
tmp += "&amp;";
else if (*it == '>')
tmp += "&gt;";
else if (*it == '\r')
tmp += "&#xD;";
else if (*it == '\n')
tmp += "&#xA;";
else
tmp += *it;
}
return tmp;
}
void DynamicProperty::Save (Base::Writer &writer) const
{
//extenions must be saved first, as they need to be read and initialised before properties (as

View File

@@ -118,8 +118,6 @@ public:
//@}
private:
/// Encodes an attribute upon saving.
std::string encodeAttribute(const std::string&) const;
std::string getUniquePropertyName(const char *Name) const;
private:

View File

@@ -155,33 +155,6 @@ void Property::Paste(const Property& /*from*/)
assert(0);
}
std::string Property::encodeAttribute(const std::string& str)
{
std::string tmp;
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
if (*it == '<')
tmp += "&lt;";
else if (*it == '\"')
tmp += "&quot;";
else if (*it == '\'')
tmp += "&apos;";
else if (*it == '&')
tmp += "&amp;";
else if (*it == '>')
tmp += "&gt;";
else if (*it == '\r')
tmp += "&#13;";
else if (*it == '\n')
tmp += "&#10;";
else if (*it == '\t')
tmp += "&#9;";
else
tmp += *it;
}
return tmp;
}
//**************************************************************************
//**************************************************************************
// PropertyLists

View File

@@ -149,8 +149,6 @@ public:
virtual Property *Copy(void) const = 0;
/// Paste the value from the property (mainly for Undo/Redo and transactions)
virtual void Paste(const Property &from) = 0;
/// Encodes an attribute upon saving.
static std::string encodeAttribute(const std::string&);
friend class PropertyContainer;

View File

@@ -68,3 +68,30 @@ void Persistence::SaveDocFile (Writer &/*writer*/) const
void Persistence::RestoreDocFile(Reader &/*reader*/)
{
}
std::string Persistence::encodeAttribute(const std::string& str)
{
std::string tmp;
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
if (*it == '<')
tmp += "&lt;";
else if (*it == '\"')
tmp += "&quot;";
else if (*it == '\'')
tmp += "&apos;";
else if (*it == '&')
tmp += "&amp;";
else if (*it == '>')
tmp += "&gt;";
else if (*it == '\r')
tmp += "&#13;";
else if (*it == '\n')
tmp += "&#10;";
else if (*it == '\t')
tmp += "&#9;";
else
tmp += *it;
}
return tmp;
}

View File

@@ -146,6 +146,8 @@ public:
* @see Base::Reader,Base::XMLReader
*/
virtual void RestoreDocFile(Reader &/*reader*/);
/// Encodes an attribute upon saving.
static std::string encodeAttribute(const std::string&);
};
} //namespace Base

View File

@@ -175,7 +175,7 @@ unsigned int Constraint::getMemSize (void) const
void Constraint::Save (Writer &writer) const
{
std::string encodeName = App::Property::encodeAttribute(Name);
std::string encodeName = encodeAttribute(Name);
writer.Stream() << writer.ind() << "<Constrain "
<< "Name=\"" << encodeName << "\" "
<< "Type=\"" << (int)Type << "\" ";