diff --git a/src/Path.cc b/src/Path.cc deleted file mode 100644 index c8e53d2..0000000 --- a/src/Path.cc +++ /dev/null @@ -1,118 +0,0 @@ -#include "Path.h" -#include "FileReader.h" -#include -#include -#include -#include - -Path::Path(const char * path) -{ - m_path = path; - clean(); -} - -Path::Path(const std::string & path) -{ - m_path = path; - clean(); -} - -PathRef Path::dirname() -{ - if (m_path.size() == 0) - return new Path(""); - size_t i = m_path.size() - 1; - while (m_path[i] == '/') - { - if (i == 0) - return new Path("/"); - i--; - } - while (m_path[i] != '/') - { - if (i == 0) - return new Path("."); - i--; - } - while (m_path[i] == '/') - { - if (i == 0) - return new Path("/"); - i--; - } - return new Path(std::string(m_path, 0, i + 1)); -} - -PathRef Path::ext(const std::string & new_ext) -{ - if (m_path.size() == 0) - return new Path(""); - size_t i = m_path.size() - 1; - while (m_path[i] != '.') - { - if ((i == 0) || (m_path[i] == '/')) - { - i = m_path.size(); - break; - } - i--; - } - if (new_ext.size() == 0) - { - return new Path(std::string(m_path, 0, i)); - } - else if (new_ext[0] == '.') - { - return new Path(std::string(m_path, 0, i) + new_ext); - } - else - { - return new Path(std::string(m_path, 0, i) + "." + new_ext); - } -} - -PathRef Path::join(const Path & other) -{ - if (m_path.size() > 0 && *m_path.rbegin() == '/') - return new Path(m_path + other.m_path); - else - return new Path(m_path + '/' + other.m_path); -} - -bool Path::exists() -{ - struct stat st; - return stat(m_path.c_str(), &st) == 0; -} - -std::vector Path::dir_entries() -{ - std::vector rv; - DIR * dir = opendir(m_path.c_str()); - if (dir != NULL) - { - for (;;) - { - struct dirent * de = readdir(dir); - if (de == NULL) - break; - rv.push_back(std::string(de->d_name)); - } - closedir(dir); - } - return rv; -} - -bool Path::read(uint8_t ** buf, size_t * size) -{ - return FileReader::load(m_path.c_str(), buf, size); -} - -void Path::clean() -{ - for (char & c : m_path) - { - if (c == '\\') - c = '/'; - } -} diff --git a/src/Path.h b/src/Path.h deleted file mode 100644 index 686770d..0000000 --- a/src/Path.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef JES_PATH_H -#define JES_PATH_H - -#include "Ref.h" -#include -#include -#include - -class Path; -typedef Ref PathRef; -class Path -{ -public: - Path(const char * path); - Path(const std::string & path); - PathRef dirname(); - PathRef ext(const std::string & new_ext); - PathRef join(const Path & other); - const std::string & to_s() { return m_path; } - bool exists(); - std::vector dir_entries(); - bool read(uint8_t ** buf, size_t * size); -protected: - void clean(); - std::string m_path; -}; - -#endif