mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 22:47:20 +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 <Date.h>
|
||||||
#include <Duration.h>
|
#include <Duration.h>
|
||||||
#include <Task.h>
|
#include <Task.h>
|
||||||
#include <JSON.h>
|
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
#include <RX.h>
|
#include <RX.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -624,10 +623,16 @@ void Task::parseJSON (const std::string& line)
|
||||||
{
|
{
|
||||||
// Parse the whole thing.
|
// Parse the whole thing.
|
||||||
json::value* root = json::parse (line);
|
json::value* root = json::parse (line);
|
||||||
if (root->type () == json::j_object)
|
if (root &&
|
||||||
{
|
root->type () == json::j_object)
|
||||||
json::object* root_obj = (json::object*)root;
|
parseJSON ((json::object*) root);
|
||||||
|
|
||||||
|
delete root;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Task::parseJSON (const json::object* root_obj)
|
||||||
|
{
|
||||||
// For each object element...
|
// For each object element...
|
||||||
for (auto& i : root_obj->_data)
|
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"];
|
json::string* what = (json::string*)annotation->_data["description"];
|
||||||
|
|
||||||
if (! when)
|
if (! when)
|
||||||
throw format (STRING_TASK_NO_ENTRY, line);
|
throw format (STRING_TASK_NO_ENTRY, root_obj->dump ());
|
||||||
|
|
||||||
if (! what)
|
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 ();
|
std::string name = "annotation_" + Date (when->_data).toEpochString ();
|
||||||
annos.insert (std::make_pair (name, json::decode (what->_data)));
|
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 <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <JSON.h>
|
||||||
|
|
||||||
class Task : public std::map <std::string, std::string>
|
class Task : public std::map <std::string, std::string>
|
||||||
{
|
{
|
||||||
|
@ -157,6 +158,7 @@ public:
|
||||||
private:
|
private:
|
||||||
int determineVersion (const std::string&);
|
int determineVersion (const std::string&);
|
||||||
void parseJSON (const std::string&);
|
void parseJSON (const std::string&);
|
||||||
|
void parseJSON (const json::object*);
|
||||||
void parseLegacy (const std::string&);
|
void parseLegacy (const std::string&);
|
||||||
void validate_before (const std::string&, const std::string&);
|
void validate_before (const std::string&, const std::string&);
|
||||||
const std::string encode (const std::string&) const;
|
const std::string encode (const std::string&) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue