MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / findIDs

Method findIDs

src/CLI2.cpp:1298–1394  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// An ID sequence can be: a single ID: 1 a list of IDs: 1,3,5 a list of IDs: 1 3 5 a range: 5-10 or a combination: 1,3,5-10 12

Source from the content-addressed store, hash-verified

1296// or a combination: 1,3,5-10 12
1297//
1298void CLI2::findIDs() {
1299 bool changes = false;
1300
1301 if (Context::getContext().config.getBoolean("sugar")) {
1302 bool previousFilterArgWasAnOperator = false;
1303 int filterCount = 0;
1304
1305 for (const auto& a : _args) {
1306 if (a.hasTag("FILTER")) {
1307 ++filterCount;
1308
1309 if (a._lextype == Lexer::Type::number) {
1310 // Skip any number that was preceded by an operator.
1311 if (!previousFilterArgWasAnOperator) {
1312 changes = true;
1313 std::string number = a.attribute("raw");
1314 _id_ranges.emplace_back(number, number);
1315 }
1316 } else if (a._lextype == Lexer::Type::set) {
1317 // Split the ID list into elements.
1318 auto elements = split(a.attribute("raw"), ',');
1319
1320 for (auto& element : elements) {
1321 changes = true;
1322 auto hyphen = element.find('-');
1323 if (hyphen != std::string::npos)
1324 _id_ranges.emplace_back(element.substr(0, hyphen), element.substr(hyphen + 1));
1325 else
1326 _id_ranges.emplace_back(element, element);
1327 }
1328 }
1329
1330 std::string raw = a.attribute("raw");
1331 previousFilterArgWasAnOperator =
1332 (a._lextype == Lexer::Type::op && raw != "(" && raw != ")") ? true : false;
1333 }
1334 }
1335
1336 // If no IDs were found, and no filter was specified, look for number/set
1337 // listed as a MODIFICATION.
1338 std::string command = getCommand();
1339
1340 if (!_id_ranges.size() && filterCount == 0 && command != "add" && command != "log") {
1341 for (auto& a : _args) {
1342 if (a.hasTag("MODIFICATION")) {
1343 std::string raw = a.attribute("raw");
1344
1345 // For a number to be an ID, it must not contain any sign or floating
1346 // point elements.
1347 if (a._lextype == Lexer::Type::number && raw.find('.') == std::string::npos &&
1348 raw.find('e') == std::string::npos && raw.find('-') == std::string::npos) {
1349 changes = true;
1350 a.unTag("MODIFICATION");
1351 a.tag("FILTER");
1352 _id_ranges.emplace_back(raw, raw);
1353 } else if (a._lextype == Lexer::Type::set) {
1354 a.unTag("MODIFICATION");
1355 a.tag("FILTER");

Callers

nothing calls this directly

Calls 7

attributeMethod · 0.80
findMethod · 0.80
unTagMethod · 0.80
tagMethod · 0.80
decomposeMethod · 0.80
hasTagMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected