mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Helper functions
- Rescued the ::encode and ::decode funtions and put them in util.cpp. This is because 2.0 will still need to perform the same encode/decode operations without Att.cpp around.
This commit is contained in:
parent
f92b13fbf7
commit
e5acabc452
2 changed files with 57 additions and 0 deletions
54
src/util.cpp
54
src/util.cpp
|
@ -485,3 +485,57 @@ unsigned burndown_size (unsigned ntasks)
|
||||||
// Round up to max of unsigned.
|
// Round up to max of unsigned.
|
||||||
return std::numeric_limits<unsigned>::max ();
|
return std::numeric_limits<unsigned>::max ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Encode values prior to serialization.
|
||||||
|
// \t -> &tab;
|
||||||
|
// " -> &dquot;
|
||||||
|
// [ -> &open;
|
||||||
|
// ] -> &close;
|
||||||
|
// \ -> \\ (extra chars to disambiguate multi-line comment)
|
||||||
|
const std::string encode (const std::string& value)
|
||||||
|
{
|
||||||
|
std::string modified = value;
|
||||||
|
|
||||||
|
str_replace (value, "\t", "&tab;");
|
||||||
|
str_replace (value, "\"", "&dquot;");
|
||||||
|
str_replace (value, "[", "&open;");
|
||||||
|
str_replace (value, "]", "&close;");
|
||||||
|
str_replace (value, "\\", "\\\\");
|
||||||
|
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Decode values after parse.
|
||||||
|
// \t <- &tab;
|
||||||
|
// " <- " or &dquot;
|
||||||
|
// ' <- &squot;
|
||||||
|
// , <- ,
|
||||||
|
// [ <- &open;
|
||||||
|
// ] <- &close;
|
||||||
|
// : <- :
|
||||||
|
const std::string decode (const std::string& value)
|
||||||
|
{
|
||||||
|
std::string modified = value;
|
||||||
|
|
||||||
|
// Supported encodings.
|
||||||
|
str_replace (modified, "&tab;", "\t");
|
||||||
|
str_replace (modified, "&dquot;", "\"");
|
||||||
|
str_replace (modified, """, "'");
|
||||||
|
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, "&squot;", "'");
|
||||||
|
str_replace (modified, ",", ",");
|
||||||
|
str_replace (modified, ":", ":");
|
||||||
|
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -85,5 +85,8 @@ void combine (std::vector <int>&, const std::vector <int>&);
|
||||||
|
|
||||||
unsigned burndown_size (unsigned ntasks);
|
unsigned burndown_size (unsigned ntasks);
|
||||||
|
|
||||||
|
const std::string encode (const std::string&);
|
||||||
|
const std::string decode (const std::string&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue