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

Method determineVersion

src/Task.cpp:1633–1693  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

1631
1632////////////////////////////////////////////////////////////////////////////////
1633int Task::determineVersion(const std::string& line) {
1634 // Version 2 looks like:
1635 //
1636 // uuid status [tags] [attributes] description\n
1637 //
1638 // Where uuid looks like:
1639 //
1640 // 27755d92-c5e9-4c21-bd8e-c3dd9e6d3cf7
1641 //
1642 // Scan for the hyphens in the uuid, the following space, and a valid status
1643 // character.
1644 if (line[8] == '-' && line[13] == '-' && line[18] == '-' && line[23] == '-' && line[36] == ' ' &&
1645 (line[37] == '-' || line[37] == '+' || line[37] == 'X' || line[37] == 'r')) {
1646 // Version 3 looks like:
1647 //
1648 // uuid status [tags] [attributes] [annotations] description\n
1649 //
1650 // Scan for the number of [] pairs.
1651 auto tagAtts = line.find("] [", 0);
1652 auto attsAnno = line.find("] [", tagAtts + 1);
1653 auto annoDesc = line.find("] ", attsAnno + 1);
1654 if (tagAtts != std::string::npos && attsAnno != std::string::npos &&
1655 annoDesc != std::string::npos)
1656 return 3;
1657 else
1658 return 2;
1659 }
1660
1661 // Version 4 looks like:
1662 //
1663 // [name:"value" ...]
1664 //
1665 // Scan for [, ] and :".
1666 else if (line[0] == '[' && line[line.length() - 1] == ']' &&
1667 line.find("uuid:\"") != std::string::npos)
1668 return 4;
1669
1670 // Version 1 looks like:
1671 //
1672 // [tags] [attributes] description\n
1673 // X [tags] [attributes] description\n
1674 //
1675 // Scan for the first character being either the bracket or X.
1676 else if (line.find("X [") == 0 ||
1677 (line[0] == '[' && line.substr(line.length() - 1, 1) != "]" && line.length() > 3))
1678 return 1;
1679
1680 // Version 5?
1681 //
1682 // Fortunately, with the hindsight that will come with version 5, the
1683 // identifying characteristics of 1, 2, 3 and 4 may be modified such that if 5
1684 // has a UUID followed by a status, then there is still a way to differentiate
1685 // between 2, 3, 4 and 5.
1686 //
1687 // The danger is that a version 3 binary reads and misinterprets a version 4
1688 // file. This is why it is a good idea to rely on an explicit version
1689 // declaration rather than chance positioning.
1690

Callers

nothing calls this directly

Calls 1

findMethod · 0.80

Tested by

no test coverage detected