diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index f14c043f..beaa1545 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -254,7 +254,7 @@ namespace nana { namespace experimental { namespace filesystem path relative_path() const; path parent_path() const; path filename() const; - //path stem() const; + path stem() const; path extension() const; // query diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index b13e8465..061a12f7 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -225,8 +225,10 @@ namespace nana { namespace experimental { namespace filesystem //Because of No wide character version of POSIX #if defined(NANA_POSIX) const char* separators = "/"; + const char* punt = "."; #else const wchar_t* separators = L"/\\"; + const wchar_t* punt = L"."; #endif //class file_status @@ -453,6 +455,22 @@ namespace nana { namespace experimental { namespace filesystem return{ pathstr_ }; } + path path::stem() const + { + auto pos = pathstr_.find_last_of(separators); + auto ext = pathstr_.find_last_of(punt); + + if (pos == pathstr_.npos) + pos = 0; + else + pos++; + + if (ext == pathstr_.npos || ext < pos) + return path(pathstr_.substr(pos)); + else + return path(pathstr_.substr(pos, ext-pos)); + } + void path::clear() noexcept { pathstr_.clear();