From e4a1e53064f3a677f66d36e3cdc4494ab5dcb979 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Sat, 2 Feb 2019 09:50:30 +0100 Subject: [PATCH] fixes #816 Remove only known extensions --- src/util/Path.cpp | 35 ++++++++++++++--------------------- src/util/Path.h | 2 +- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/util/Path.cpp b/src/util/Path.cpp index 090b8403..229ec4e3 100644 --- a/src/util/Path.cpp +++ b/src/util/Path.cpp @@ -2,7 +2,7 @@ #include "StringUtils.h" #include - +#include Path::Path() { @@ -124,32 +124,25 @@ bool Path::hasExtension(string ext) return pathExt == ext; } +#define REMOVE_EXTENSION(ext) \ + if (StringUtils::endsWith(plower, ext)) \ + { \ + path = path.substr(0, path.length() - strlen(ext)); \ + return;\ + } + /** - * Clear the extension (last .xyz or .pdf.xoj, .pdf.xopp) + * Clear the the last known extension (last .pdf, .pdf.xoj, .pdf.xopp etc.) */ void Path::clearExtensions() { string plower = StringUtils::toLowerCase(path); - if (StringUtils::endsWith(plower, ".pdf.xoj")) - { - path = path.substr(0, path.length() - 8); - return; - } - - if (StringUtils::endsWith(plower, ".pdf.xopp")) - { - path = path.substr(0, path.length() - 9); - return; - } - - size_t separator = path.find_last_of("/\\"); - size_t dotPos = path.find_last_of("."); - if (dotPos == string::npos || (dotPos < separator && separator != string::npos)) - { - return; - } - path = path.substr(0, dotPos); + REMOVE_EXTENSION(".pdf.xoj"); + REMOVE_EXTENSION(".pdf.xopp"); + REMOVE_EXTENSION(".xoj"); + REMOVE_EXTENSION(".xopp"); + REMOVE_EXTENSION(".pdf"); } /** diff --git a/src/util/Path.h b/src/util/Path.h index 94db6e6b..2b7aacc0 100644 --- a/src/util/Path.h +++ b/src/util/Path.h @@ -73,7 +73,7 @@ public: bool hasExtension(string ext); /** - * Clear the extension (last .xyz or .pdf.xoj, .pdf.xopp) + * Clear the the last known extension (last .pdf, .pdf.xoj, .pdf.xopp etc.) */ void clearExtensions();