summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp61
1 files changed, 32 insertions, 29 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
index 30b32f81d1f..9f9b295ad62 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FilePath.cpp
@@ -2,7 +2,7 @@
** FilePath.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2017 Martin Gieseking <martin.gieseking@uos.de> **
** **
** This program is free software; you can redistribute it and/or **
** modify it under the terms of the GNU General Public License as **
@@ -20,10 +20,10 @@
#include <config.h>
#include <cctype>
-#include "FilePath.h"
-#include "FileSystem.h"
-#include "MessageException.h"
-#include "macros.h"
+#include "FilePath.hpp"
+#include "FileSystem.hpp"
+#include "MessageException.hpp"
+#include "utility.hpp"
using namespace std;
@@ -41,7 +41,7 @@ static string& single_slashes (string &str) {
static char strip_drive_letter (string &path) {
char letter = 0;
if (path.length() >= 2 && path[1] == ':' && isalpha(path[0])) {
- letter = tolower(path[0]);
+ letter = path[0];
path.erase(0, 2);
}
return letter;
@@ -66,12 +66,19 @@ static char adapt_current_path (string &path, char target_drive) {
return target_drive;
}
+#endif
-static void tolower (string &str) {
- for (size_t i=0; i < str.length(); ++i)
- str[i] = tolower(str[i]);
-}
+
+bool FilePath::Directory::operator == (const Directory &dir) const {
+ string dirstr1 = _dirstr;
+ string dirstr2 = dir._dirstr;
+#ifdef _WIN32
+ // letter case is not significant on Windows systems
+ util::tolower(dirstr1);
+ util::tolower(dirstr2);
#endif
+ return dirstr1 == dirstr2;
+}
/** Constructs a FilePath object from a given path. Relative paths are
@@ -86,7 +93,7 @@ FilePath::FilePath (const string &path) {
* @param[in] path absolute or relative path to a file or directory
* @param[in] isfile true if 'path' references a file, false if a directory is referenced
* @param[in] current_dir if 'path' is a relative path expression it will be related to 'current_dir' */
-FilePath::FilePath (const string &path, bool isfile, string current_dir) {
+FilePath::FilePath (const string &path, bool isfile, const string &current_dir) {
init(path, isfile, current_dir);
}
@@ -99,7 +106,6 @@ void FilePath::init (string path, bool isfile, string current_dir) {
single_slashes(path);
single_slashes(current_dir);
#ifdef _WIN32
- tolower(path);
path = FileSystem::adaptPathSeperators(path);
_drive = strip_drive_letter(path);
#endif
@@ -114,7 +120,6 @@ void FilePath::init (string path, bool isfile, string current_dir) {
if (current_dir.empty())
current_dir = FileSystem::getcwd();
#ifdef _WIN32
- tolower(current_dir);
_drive = adapt_current_path(current_dir, _drive);
#endif
if (!path.empty()) {
@@ -132,13 +137,13 @@ void FilePath::init (string path, bool isfile, string current_dir) {
}
path.insert(0, current_dir + "/");
string elem;
- FORALL (path, string::const_iterator, it) {
- if (*it == '/') {
+ for (char c : path) {
+ if (c != '/')
+ elem += c;
+ else {
add(elem);
elem.clear();
}
- else
- elem += *it;
}
add(elem);
}
@@ -200,9 +205,8 @@ string FilePath::basename () const {
* @return the absolute path string */
string FilePath::absolute (bool with_filename) const {
string path;
- FORALL (_dirs, ConstIterator, it) {
- path += "/" + *it;
- }
+ for (const Directory &dir : _dirs)
+ path += "/" + string(dir);
if (path.empty())
path = "/";
if (with_filename && !_fname.empty())
@@ -233,17 +237,17 @@ string FilePath::relative (string reldir, bool with_filename) const {
FilePath rel(reldir, false);
string path;
#ifdef _WIN32
- if (rel._drive && _drive && rel._drive != _drive)
+ if (rel._drive && _drive && tolower(rel._drive) != tolower(_drive))
path += string(1, _drive) + ":";
#endif
- ConstIterator i = _dirs.begin();
- ConstIterator j = rel._dirs.begin();
- while (i != _dirs.end() && j != rel._dirs.end() && *i == *j)
- ++i, ++j;
- for (; j != rel._dirs.end(); ++j)
+ auto it1 = _dirs.begin();
+ auto it2 = rel._dirs.begin();
+ while (it1 != _dirs.end() && it2 != rel._dirs.end() && *it1 == *it2)
+ ++it1, ++it2;
+ for (; it2 != rel._dirs.end(); ++it2)
path += "../";
- for (; i != _dirs.end(); ++i)
- path += *i + "/";
+ for (; it1 != _dirs.end(); ++it1)
+ path += string(*it1) + "/";
if (!path.empty())
path.erase(path.length()-1, 1); // remove trailing slash
if (with_filename && !_fname.empty()) {
@@ -255,4 +259,3 @@ string FilePath::relative (string reldir, bool with_filename) const {
path = ".";
return single_slashes(path);
}
-