move encodeAttribute from Property to Persitence to avoid code duplication
This commit is contained in:
@@ -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 += "<";
|
||||
else if (*it == '"')
|
||||
tmp += """;
|
||||
else if (*it == '\'')
|
||||
tmp += "'";
|
||||
else if (*it == '&')
|
||||
tmp += "&";
|
||||
else if (*it == '>')
|
||||
tmp += ">";
|
||||
else if (*it == '\r')
|
||||
tmp += "
";
|
||||
else if (*it == '\n')
|
||||
tmp += "
";
|
||||
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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 += "<";
|
||||
else if (*it == '\"')
|
||||
tmp += """;
|
||||
else if (*it == '\'')
|
||||
tmp += "'";
|
||||
else if (*it == '&')
|
||||
tmp += "&";
|
||||
else if (*it == '>')
|
||||
tmp += ">";
|
||||
else if (*it == '\r')
|
||||
tmp += " ";
|
||||
else if (*it == '\n')
|
||||
tmp += " ";
|
||||
else if (*it == '\t')
|
||||
tmp += "	";
|
||||
else
|
||||
tmp += *it;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// PropertyLists
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 += "<";
|
||||
else if (*it == '\"')
|
||||
tmp += """;
|
||||
else if (*it == '\'')
|
||||
tmp += "'";
|
||||
else if (*it == '&')
|
||||
tmp += "&";
|
||||
else if (*it == '>')
|
||||
tmp += ">";
|
||||
else if (*it == '\r')
|
||||
tmp += " ";
|
||||
else if (*it == '\n')
|
||||
tmp += " ";
|
||||
else if (*it == '\t')
|
||||
tmp += "	";
|
||||
else
|
||||
tmp += *it;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 << "\" ";
|
||||
|
||||
Reference in New Issue
Block a user