diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-10-30 00:56:43 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-10-30 00:56:43 +0100 |
commit | f941119fbd89b5677a2895eee3232fa76389b4b5 (patch) | |
tree | 7d761d3c8189c06dda83e3fa88f281a24ab46e4b /depends/util | |
parent | c46292c9b1c153f2d17554690e90db1c8efe4d23 (diff) | |
parent | 44823324f9f489adf957a459bac5dd4d0693e85e (diff) | |
download | PrismLauncher-f941119fbd89b5677a2895eee3232fa76389b4b5.tar.gz PrismLauncher-f941119fbd89b5677a2895eee3232fa76389b4b5.tar.bz2 PrismLauncher-f941119fbd89b5677a2895eee3232fa76389b4b5.zip |
Merge branch 'develop'
Diffstat (limited to 'depends/util')
-rw-r--r-- | depends/util/include/cmdutils.h | 9 | ||||
-rw-r--r-- | depends/util/include/pathutils.h | 10 | ||||
-rw-r--r-- | depends/util/src/cmdutils.cpp | 15 | ||||
-rw-r--r-- | depends/util/src/pathutils.cpp | 24 |
4 files changed, 37 insertions, 21 deletions
diff --git a/depends/util/include/cmdutils.h b/depends/util/include/cmdutils.h index 93fef9ff..bab5a9fa 100644 --- a/depends/util/include/cmdutils.h +++ b/depends/util/include/cmdutils.h @@ -19,6 +19,7 @@ #define CMDUTILS_H #include <exception> +#include <stdexcept> #include <QString> #include <QVariant> @@ -83,16 +84,10 @@ enum Enum /** * @brief The ParsingError class */ -class LIBUTIL_EXPORT ParsingError : public std::exception +class LIBUTIL_EXPORT ParsingError : public std::runtime_error { public: ParsingError(const QString &what); - ParsingError(const ParsingError &e); - ~ParsingError() throw() {} - const char *what() const throw(); - QString qwhat() const; -private: - QString m_what; }; /** diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h index cea3a39a..c892c115 100644 --- a/depends/util/include/pathutils.h +++ b/depends/util/include/pathutils.h @@ -25,6 +25,16 @@ LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3); LIBUTIL_EXPORT QString AbsolutePath(QString path); +/** + * Normalize path + * + * Any paths inside the current directory will be normalized to relative paths (to current) + * Other paths will be made absolute + * + * Returns false if the path logic somehow filed (and normalizedPath in invalid) + */ +QString NormalizePath(QString path); + LIBUTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); LIBUTIL_EXPORT QString DirNameFromString(QString string, QString inDir = "."); diff --git a/depends/util/src/cmdutils.cpp b/depends/util/src/cmdutils.cpp index 80ba719d..b9cab717 100644 --- a/depends/util/src/cmdutils.cpp +++ b/depends/util/src/cmdutils.cpp @@ -463,21 +463,8 @@ void Parser::getPrefix(QString &opt, QString &flag) // ParsingError ParsingError::ParsingError(const QString &what) +:std::runtime_error(what.toStdString()) { - m_what = what; -} -ParsingError::ParsingError(const ParsingError &e) -{ - m_what = e.m_what; -} - -const char *ParsingError::what() const throw() -{ - return m_what.toLocal8Bit().constData(); -} -QString ParsingError::qwhat() const -{ - return m_what; } } diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp index 4c24fa5d..590ac89d 100644 --- a/depends/util/src/pathutils.cpp +++ b/depends/util/src/pathutils.cpp @@ -39,6 +39,30 @@ QString AbsolutePath(QString path) return QFileInfo(path).absolutePath(); } +/** + * Normalize path + * + * Any paths inside the current directory will be normalized to relative paths (to current) + * Other paths will be made absolute + */ +QString NormalizePath(QString path) +{ + QDir a = QDir::currentPath(); + QString currentAbsolute = a.absolutePath(); + + QDir b(path); + QString newAbsolute = b.absolutePath(); + + if (newAbsolute.startsWith(currentAbsolute)) + { + return a.relativeFilePath(newAbsolute); + } + else + { + return newAbsolute; + } +} + QString badFilenameChars = "\"\\/?<>:*|!"; QString RemoveInvalidFilenameChars(QString string, QChar replaceWith) |