mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
Task
- Migrated util.cpp encode and decode functions because this is the only place they are used.
This commit is contained in:
parent
bffc7a2ac8
commit
a7171193ca
2 changed files with 49 additions and 0 deletions
47
src/Task.cpp
47
src/Task.cpp
|
@ -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 "
|
||||
// , <- ,
|
||||
// [ <- &open;
|
||||
// ] <- &close;
|
||||
// : <- :
|
||||
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, """, "'");
|
||||
str_replace (modified, "&squot;", "'"); // Deprecated 2.0
|
||||
str_replace (modified, ",", ","); // Deprecated 2.0
|
||||
str_replace (modified, ":", ":"); // Deprecated 2.0
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Task::determineVersion (const std::string& line)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue