From: Ingo Ruhnke Date: Sun, 10 Aug 2014 21:52:16 +0000 (+0200) Subject: Added FileSystem::join("dir", "file") -> "dir/file" X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3df4d4cb8ab803dec1380a8866f29bbab1e03739;p=supertux.git Added FileSystem::join("dir", "file") -> "dir/file" --- diff --git a/src/util/file_system.cpp b/src/util/file_system.cpp index a89b1b458..524d4a530 100644 --- a/src/util/file_system.cpp +++ b/src/util/file_system.cpp @@ -103,6 +103,22 @@ std::string normalize(const std::string& filename) return result.str(); } +std::string join(const std::string& lhs, const std::string& rhs) +{ + if (lhs.empty()) + { + return rhs; + } + else if (lhs.back() == '/') + { + return lhs + rhs; + } + else + { + return lhs + "/" + rhs; + } +} + } // namespace FileSystem /* EOF */ diff --git a/src/util/file_system.hpp b/src/util/file_system.hpp index 5cdda27fb..0e9783504 100644 --- a/src/util/file_system.hpp +++ b/src/util/file_system.hpp @@ -40,6 +40,11 @@ std::string strip_extension(const std::string& filename); */ std::string normalize(const std::string& filename); +/** + * join two filenames join("foo", "bar") -> "foo/bar" + */ +std::string join(const std::string& lhs, const std::string& rhs); + } // namespace FileSystem #endif