- Migrated util.cpp encode and decode functions because this is the only place
  they are used.
This commit is contained in:
Paul Beckingham 2014-09-07 17:23:16 -04:00
parent bffc7a2ac8
commit a7171193ca
2 changed files with 49 additions and 0 deletions

View file

@ -1617,6 +1617,53 @@ void Task::validate_before (const std::string& left, const std::string& right)
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Encode values prior to serialization.
// [ -> &open;
// ] -> &close;
const std::string Task::encode (const std::string& value) const
{
std::string modified = value;
str_replace (modified, "[", "&open;");
str_replace (modified, "]", "&close;");
return modified;
}
////////////////////////////////////////////////////////////////////////////////
// Decode values after parse.
// " <- &dquot;
// ' <- &squot; or &quot;
// , <- &comma;
// [ <- &open;
// ] <- &close;
// : <- &colon;
const std::string Task::decode (const std::string& value) const
{
if (value.find ('&') != std::string::npos)
{
std::string modified = value;
// Supported encodings.
str_replace (modified, "&open;", "[");
str_replace (modified, "&close;", "]");
// Support for deprecated encodings. These cannot be removed or old files
// will not be parsable. Not just old files - completed.data can contain
// tasks formatted/encoded using these.
str_replace (modified, "&dquot;", "\"");
str_replace (modified, "&quot;", "'");
str_replace (modified, "&squot;", "'"); // Deprecated 2.0
str_replace (modified, "&comma;", ","); // Deprecated 2.0
str_replace (modified, "&colon;", ":"); // Deprecated 2.0
return modified;
}
return value;
}
////////////////////////////////////////////////////////////////////////////////
int Task::determineVersion (const std::string& line)
{

View file

@ -164,6 +164,8 @@ private:
void parseJSON (const std::string&);
void parseLegacy (const std::string&);
void validate_before (const std::string&, const std::string&);
const std::string encode (const std::string&) const;
const std::string decode (const std::string&) const;
public:
float urgency_priority () const;