mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Annotation Bug
- Fixed DOM lookup of special-case attributes: id and urgency are not stored in the usual manner, and must be handled differently. - Removed the responsibility of DOM to evaluate literals, because they are handled more effectively in A3::tokenize. - Fixed old code that assumed ".id" instead of "id". - Removed unnecessary diag call from annotate.t.
This commit is contained in:
parent
1884223a2e
commit
e61e08c2ca
3 changed files with 11 additions and 70 deletions
77
src/DOM.cpp
77
src/DOM.cpp
|
@ -97,14 +97,9 @@ const std::string DOM::get (const std::string& name)
|
|||
|
||||
int len = name.length ();
|
||||
Nibbler n (name);
|
||||
std::string copy_name (name);
|
||||
|
||||
// Primitives
|
||||
if (is_literal (copy_name))
|
||||
return /*_cache[name] =*/ copy_name;
|
||||
|
||||
// rc. --> context.config
|
||||
else if (len > 3 &&
|
||||
if (len > 3 &&
|
||||
name.substr (0, 3) == "rc.")
|
||||
{
|
||||
return /*_cache[name] =*/ context.config.get (name.substr (3));
|
||||
|
@ -232,14 +227,10 @@ const std::string DOM::get (const std::string& name, const Task& task)
|
|||
std::string uuid;
|
||||
std::string canonical;
|
||||
|
||||
// Primitives
|
||||
std::string copy_name (name);
|
||||
if (is_literal (copy_name))
|
||||
return /*_cache[name] =*/ copy_name;
|
||||
|
||||
// <attr>
|
||||
else if (A3::is_attribute (name, canonical))
|
||||
return task.get (canonical);
|
||||
if (name == "id") return format (task.id);
|
||||
else if (name == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else if (A3::is_attribute (name, canonical)) return task.get (canonical);
|
||||
|
||||
// <id>.<name>
|
||||
else if (n.getInt (id))
|
||||
|
@ -250,9 +241,9 @@ const std::string DOM::get (const std::string& name, const Task& task)
|
|||
std::string attr;
|
||||
n.getUntilEOS (attr);
|
||||
|
||||
if (attr == "id") return format (task.id);
|
||||
else if (attr == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else return task.get (attr);
|
||||
if (attr == "id") return format (task.id);
|
||||
else if (attr == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else if (A3::is_attribute (name, canonical)) return task.get (canonical);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,22 +256,17 @@ const std::string DOM::get (const std::string& name, const Task& task)
|
|||
std::string attr;
|
||||
n.getUntilEOS (attr);
|
||||
|
||||
if (attr == "id") return format (task.id);
|
||||
else if (attr == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else return task.get (attr);
|
||||
if (name == "id") return format (task.id);
|
||||
else if (name == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else if (A3::is_attribute (name, canonical)) return task.get (canonical);
|
||||
}
|
||||
}
|
||||
|
||||
// [<task>.]<name>
|
||||
if (name == "id") return format (task.id);
|
||||
else if (name == "urgency") return format (task.urgency_c (), 4, 3);
|
||||
else if (task.has (name.substr (1))) return task.get (name.substr (1));
|
||||
|
||||
// Delegate to the context-free version of DOM::get.
|
||||
return this->get (name);
|
||||
}
|
||||
|
||||
// TODO Need a context-specific DOM::set.
|
||||
// TODO Need a context-specific DOM::set. For Lua.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DOM::set (const std::string& name, const std::string& value)
|
||||
|
@ -300,44 +286,3 @@ void DOM::set (const std::string& name, const std::string& value)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool DOM::is_literal (std::string& input)
|
||||
{
|
||||
std::string s;
|
||||
double d;
|
||||
int i;
|
||||
|
||||
// Date?
|
||||
if (Date::valid (input, context.config.get ("dateformat")))
|
||||
{
|
||||
input = Date (input).toEpochString ();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Duration?
|
||||
if (Duration::valid (input))
|
||||
return true;
|
||||
|
||||
// TODO Quoted Date?
|
||||
// TODO Quoted Duration?
|
||||
|
||||
// String?
|
||||
Nibbler n (input);
|
||||
if ((n.getQuoted ('"', s) ||
|
||||
n.getQuoted ('\'', s)) &&
|
||||
n.depleted ())
|
||||
return true;
|
||||
|
||||
// Number?
|
||||
n = Nibbler (input);
|
||||
if (n.getNumber (d) && n.depleted ())
|
||||
return true;
|
||||
|
||||
// Integer?
|
||||
n = Nibbler (input);
|
||||
if (n.getInt (i) && n.depleted ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -43,9 +43,6 @@ public:
|
|||
const std::string get (const std::string&, const Task&);
|
||||
void set (const std::string&, const std::string&);
|
||||
|
||||
private:
|
||||
bool is_literal (std::string&);
|
||||
|
||||
private:
|
||||
std::map <std::string, std::string> _cache;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue