implement filesystem path stem() in nana
This commit is contained in:
parent
2b6c8e0180
commit
ea3082239b
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user