From a6dfd3da74ef34fea821d799ade60a07eccd8276 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 11 Aug 2018 07:14:48 +0200 Subject: [PATCH] Changed get_filepath() from string to filesystem::path --- CMakeLists.txt | 2 +- src/xdgjson.cpp | 17 +++-------------- src/xdgjson.hpp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a8f5f7..6f35860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project(xdgjson - VERSION 0.1.0 + VERSION 0.2.0 LANGUAGES CXX ) diff --git a/src/xdgjson.cpp b/src/xdgjson.cpp index 5c5782f..01869ed 100644 --- a/src/xdgjson.cpp +++ b/src/xdgjson.cpp @@ -2,22 +2,11 @@ * Author: tastytea */ -#if __cplusplus >= 201703L - #include -#else - #include -#endif #include #include #include #include "xdgjson.hpp" -#if __cplusplus >= 201703L - namespace fs = std::filesystem; -#else - namespace fs = std::experimental::filesystem; -#endif - xdgjson::xdgjson(const string &filename, const string &subdir) : _json() { @@ -28,13 +17,13 @@ xdgjson::xdgjson(const string &filename, const string &subdir) if (!subdir.empty()) { - _filepath += '/' + subdir; + _filepath /= subdir; if (!fs::exists(_filepath)) { fs::create_directory(_filepath); } } - _filepath += '/' + filename; + _filepath /= filename; } const bool xdgjson::read() @@ -77,7 +66,7 @@ Json::Value &xdgjson::get_json() return _json; } -const string xdgjson::get_filepath() const +const fs::path xdgjson::get_filepath() const { return _filepath; } diff --git a/src/xdgjson.hpp b/src/xdgjson.hpp index 11b58c4..b1138ff 100644 --- a/src/xdgjson.hpp +++ b/src/xdgjson.hpp @@ -5,9 +5,19 @@ #ifndef XDGJSON_HPP #define XDGJSON_HPP +#if __cplusplus >= 201703L + #include +#else + #include +#endif #include #include +#if __cplusplus >= 201703L + namespace fs = std::filesystem; +#else + namespace fs = std::experimental::filesystem; +#endif using std::string; class xdgjson @@ -53,7 +63,7 @@ public: /*! * @brief Returns the complete filepath */ - const string get_filepath() const; + const fs::path get_filepath() const; private: /*! @@ -64,7 +74,7 @@ private: /*! * Complete filepath */ - string _filepath; + fs::path _filepath; }; /*!