mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Task: Added a code path allowing parseJSON to be handed a JSON tree
This commit is contained in:
parent
965b7cfd3d
commit
5995320164
2 changed files with 102 additions and 98 deletions
20
src/Task.cpp
20
src/Task.cpp
|
@ -41,7 +41,6 @@
|
|||
#include <Date.h>
|
||||
#include <Duration.h>
|
||||
#include <Task.h>
|
||||
#include <JSON.h>
|
||||
#ifdef PRODUCT_TASKWARRIOR
|
||||
#include <RX.h>
|
||||
#endif
|
||||
|
@ -624,10 +623,16 @@ void Task::parseJSON (const std::string& line)
|
|||
{
|
||||
// Parse the whole thing.
|
||||
json::value* root = json::parse (line);
|
||||
if (root->type () == json::j_object)
|
||||
{
|
||||
json::object* root_obj = (json::object*)root;
|
||||
if (root &&
|
||||
root->type () == json::j_object)
|
||||
parseJSON ((json::object*) root);
|
||||
|
||||
delete root;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::parseJSON (const json::object* root_obj)
|
||||
{
|
||||
// For each object element...
|
||||
for (auto& i : root_obj->_data)
|
||||
{
|
||||
|
@ -702,10 +707,10 @@ void Task::parseJSON (const std::string& line)
|
|||
json::string* what = (json::string*)annotation->_data["description"];
|
||||
|
||||
if (! when)
|
||||
throw format (STRING_TASK_NO_ENTRY, line);
|
||||
throw format (STRING_TASK_NO_ENTRY, root_obj->dump ());
|
||||
|
||||
if (! what)
|
||||
throw format (STRING_TASK_NO_DESC, line);
|
||||
throw format (STRING_TASK_NO_DESC, root_obj->dump ());
|
||||
|
||||
std::string name = "annotation_" + Date (when->_data).toEpochString ();
|
||||
annos.insert (std::make_pair (name, json::decode (what->_data)));
|
||||
|
@ -730,9 +735,6 @@ void Task::parseJSON (const std::string& line)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete root;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <JSON.h>
|
||||
|
||||
class Task : public std::map <std::string, std::string>
|
||||
{
|
||||
|
@ -157,6 +158,7 @@ public:
|
|||
private:
|
||||
int determineVersion (const std::string&);
|
||||
void parseJSON (const std::string&);
|
||||
void parseJSON (const json::object*);
|
||||
void parseLegacy (const std::string&);
|
||||
void validate_before (const std::string&, const std::string&);
|
||||
const std::string encode (const std::string&) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue