implement filesystem path stem() in nana

This commit is contained in:
Vina Rodriguez 2019-03-19 20:04:31 +01:00
parent 2b6c8e0180
commit ea3082239b
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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();