From 9fc9e5cf70adf1b2fd89752f3750c511fa7730df Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 31 Aug 2015 13:02:21 -0400 Subject: Add a new "PathToAbsolute()" function to LuminaUtils for converting a possible relative path to an absolute path (for input path validation/checking). --- libLumina/LuminaUtils.cpp | 12 ++++++++++++ libLumina/LuminaUtils.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 63875172..ba3a8ef8 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -121,6 +121,18 @@ QStringList LUtils::listSubDirectories(QString dir, bool recursive){ return out; } +QString LUtils::PathToAbsolute(QString path){ + //Convert an input path to an absolute path (this does not check existance ot anything) + if(path.startsWith("/")){ return path; } //already an absolute path + if(path.startsWith("~")){ path = path.remove(1); path.prepend(QDir::homePath()); } + if(!path.startsWith("/")){ + //Must be a relative path + if(path.startsWith("./")){ path = path.remove(2); } + path.prepend( QDir::currentPath()+"/"); + } + return path; +} + QStringList LUtils::imageExtensions(){ //Note that all the image extensions are lowercase!! static QStringList imgExtensions; diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h index b479e3ec..06552d1f 100644 --- a/libLumina/LuminaUtils.h +++ b/libLumina/LuminaUtils.h @@ -45,6 +45,9 @@ public: //List all the sub-directories of a parent dir (recursive) static QStringList listSubDirectories(QString dir, bool recursive = true); + //Convert an input file/dir path to an absolute file path + static QString PathToAbsolute(QString path); + //Get the list of all file extensions which Qt can read (lowercase) static QStringList imageExtensions(); -- cgit