From 0558b6c7aa95fd04fcc5251f376a93cd0f08e609 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 20 Nov 2021 11:41:18 -0500 Subject: [PATCH] ColDepends: Recognize and properly handle ID ranges --- src/columns/ColDepends.cpp | 18 +++++++++++++++++- src/util.cpp | 8 ++++++++ src/util.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/columns/ColDepends.cpp b/src/columns/ColDepends.cpp index 227c1944c..551af3ec5 100644 --- a/src/columns/ColDepends.cpp +++ b/src/columns/ColDepends.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #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); } } } diff --git a/src/util.cpp b/src/util.cpp index b7cc48c47..02a97c44c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,6 +25,7 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include // If is included, put it after , because it includes // , 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); +} diff --git a/src/util.h b/src/util.h index e71b99222..f900e989e 100644 --- a/src/util.h +++ b/src/util.h @@ -63,6 +63,7 @@ const std::vector extractParents ( bool nontrivial (const std::string&); const char* optionalBlankLine (); void setHeaderUnderline (Table&); +bool extractLongInteger (const std::string&, long&); #endif ////////////////////////////////////////////////////////////////////////////////