mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Code Cleanup
- Cmake was not updating HAVE_ST_BIRTHTIME. - NIBBLER_FEATURE_DATE was not properly applied everywhere. - FEATURE_COLOR was not properly set. - Some source files failed to include cmake.h, and therefore were not properly - Removed inefficient use of std::string::substr for guaranteed single character strings. - Integrated Directory::cd. - Integrated File::ctime, ::btime. - Integrated Path::operator+. - Integrated Nibbler::getDigit{2,4,6}. - Integrated HighResTimer. enabling/disabling code. - All Path objects now expanded internally to absolute form. - Modified unit tests to accomodate absolute paths. - Merged new nibbler.t.cpp tests. - Made various methods const. - Includes removed from some files, added to others.
This commit is contained in:
parent
ebaf09cbe0
commit
a1132f0028
24 changed files with 254 additions and 39 deletions
29
src/Path.cpp
29
src/Path.cpp
|
@ -33,6 +33,7 @@
|
|||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <Path.h>
|
||||
#include <cmake.h>
|
||||
|
||||
|
@ -88,6 +89,13 @@ bool Path::operator== (const Path& other)
|
|||
return _data == other._data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Path& Path::operator+= (const std::string& dir)
|
||||
{
|
||||
_data += "/" + dir;
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Path::operator std::string () const
|
||||
{
|
||||
|
@ -153,7 +161,7 @@ bool Path::is_directory () const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Path::is_absolute () const
|
||||
{
|
||||
if (_data.length () && _data.substr (0, 1) == "/")
|
||||
if (_data.length () && _data[0] == '/')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -197,6 +205,8 @@ bool Path::rename (const std::string& new_name)
|
|||
// ~ --> /home/user
|
||||
// ~foo/x --> /home/foo/s
|
||||
// ~/x --> /home/foo/x
|
||||
// ./x --> $PWD/x
|
||||
// x --> $PWD/x
|
||||
std::string Path::expand (const std::string& in)
|
||||
{
|
||||
std::string copy = in;
|
||||
|
@ -234,6 +244,23 @@ std::string Path::expand (const std::string& in)
|
|||
}
|
||||
}
|
||||
|
||||
// Relative paths
|
||||
else if (in.length () > 2 &&
|
||||
in.substr (0, 2) == "./")
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
getcwd (buf, PATH_MAX - 1);
|
||||
copy = std::string (buf) + "/" + in.substr (2);
|
||||
}
|
||||
else if (in.length () > 1 &&
|
||||
in[0] != '.' &&
|
||||
in[0] != '/')
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
getcwd (buf, PATH_MAX - 1);
|
||||
copy = std::string (buf) + "/" + in;
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue