mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ColDepends: Recognize and properly handle ID ranges
This commit is contained in:
parent
774f6df210
commit
0558b6c7aa
3 changed files with 26 additions and 1 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <format.h>
|
||||
#include <utf8.h>
|
||||
#include <main.h>
|
||||
#include <util.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STRING_COLUMN_LABEL_DEP "Depends"
|
||||
|
@ -161,10 +162,25 @@ void ColumnDepends::modify (Task& task, const std::string& value)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto hyphen = dep.find ('-');
|
||||
long lower, upper; // For ID ranges
|
||||
|
||||
// UUID
|
||||
if (dep.length () == 36)
|
||||
task.addDependency (dep);
|
||||
// ID range
|
||||
else if (dep.find ('-') != std::string::npos &&
|
||||
extractLongInteger (dep.substr (0, hyphen), lower) &&
|
||||
extractLongInteger (dep.substr (hyphen + 1), upper))
|
||||
{
|
||||
for (long i = lower; i <= upper; i++)
|
||||
task.addDependency(i);
|
||||
}
|
||||
// Simple ID
|
||||
else if (extractLongInteger (dep, lower))
|
||||
task.addDependency (lower);
|
||||
else
|
||||
task.addDependency (strtol (dep.c_str (), nullptr, 10));
|
||||
throw format ("Invalid dependency value: '{1}'", dep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <format.h>
|
||||
#include <shared.h>
|
||||
// If <iostream> is included, put it after <stdio.h>, because it includes
|
||||
// <stdio.h>, and therefore would ignore the _WITH_GETLINE.
|
||||
|
@ -309,3 +310,10 @@ void setHeaderUnderline (Table& table)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Perform strtol on a string and check if the extracted value matches.
|
||||
//
|
||||
bool extractLongInteger (const std::string& input, long& output)
|
||||
{
|
||||
output = strtol (input.c_str (), nullptr, 10);
|
||||
return (format ("{1}", output) == input);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ const std::vector <std::string> extractParents (
|
|||
bool nontrivial (const std::string&);
|
||||
const char* optionalBlankLine ();
|
||||
void setHeaderUnderline (Table&);
|
||||
bool extractLongInteger (const std::string&, long&);
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue