mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-12 22:17:06 +00:00
cmSystemTools: Add string_view FileName and Extension Getter
This commit is contained in:
committed by
Brad King
parent
f53296147f
commit
c99ea2f78e
@@ -4392,3 +4392,31 @@ char cmSystemTools::GetSystemPathlistSeparator()
|
||||
return ':';
|
||||
#endif
|
||||
}
|
||||
|
||||
cm::string_view cmSystemTools::GetFilenameNameView(std::string const& filename)
|
||||
{
|
||||
// implementation mostly taken from cmsys::SystemTools
|
||||
#if defined(_WIN32) || defined(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
|
||||
cm::static_string_view separators = "/\\"_s;
|
||||
#else
|
||||
char separators = '/';
|
||||
#endif
|
||||
std::string::size_type slash_pos = filename.find_last_of(separators);
|
||||
if (slash_pos != std::string::npos) {
|
||||
return cm::string_view(filename).substr(slash_pos + 1);
|
||||
} else {
|
||||
return cm::string_view(filename);
|
||||
}
|
||||
}
|
||||
|
||||
cm::string_view cmSystemTools::GetFilenameLastExtensionView(
|
||||
std::string const& filename)
|
||||
{
|
||||
cm::string_view name = cmSystemTools::GetFilenameNameView(filename);
|
||||
cm::string_view::size_type dot_pos = name.rfind('.');
|
||||
if (dot_pos != std::string::npos) {
|
||||
return name.substr(dot_pos);
|
||||
} else {
|
||||
return cm::string_view();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,6 +705,16 @@ public:
|
||||
/** Get the system path separator character */
|
||||
static char GetSystemPathlistSeparator();
|
||||
|
||||
/** Return subview of the full filename (i.e. file name without path) */
|
||||
static cm::string_view GetFilenameNameView(std::string const& filename);
|
||||
|
||||
/**
|
||||
* Return subview of file extension of a full filename (dot included).
|
||||
* Warning: this is the shortest extension (for example: .gz of .tar.gz)
|
||||
*/
|
||||
static cm::string_view GetFilenameLastExtensionView(
|
||||
std::string const& filename);
|
||||
|
||||
private:
|
||||
static bool s_ForceUnixPaths;
|
||||
static bool s_RunCommandHideConsole;
|
||||
|
||||
Reference in New Issue
Block a user