mirror of
https://github.com/holub/mame
synced 2025-10-06 17:08:28 +03:00
Deeper C++-ification
This commit is contained in:
parent
130e05cc4e
commit
2bd5932b42
@ -1272,17 +1272,21 @@ core_file::core_file()
|
|||||||
|
|
||||||
std::string core_filename_extract_base(const std::string &name, bool strip_extension)
|
std::string core_filename_extract_base(const std::string &name, bool strip_extension)
|
||||||
{
|
{
|
||||||
/* find the start of the name */
|
// find the start of the basename
|
||||||
const char *start = name.c_str() + name.length();
|
auto start = name.end();
|
||||||
while (start > name.c_str() && !util::is_directory_separator(start[-1]))
|
while (start != name.begin() && !util::is_directory_separator(start[-1]))
|
||||||
start--;
|
start--;
|
||||||
|
|
||||||
/* copy the rest into an astring */
|
// find the end of the basename
|
||||||
std::string result(start);
|
auto chop_position = strip_extension
|
||||||
|
? name.find_last_of('.')
|
||||||
|
: std::string::npos;
|
||||||
|
auto end = chop_position != std::string::npos
|
||||||
|
? name.begin() + chop_position
|
||||||
|
: name.end();
|
||||||
|
|
||||||
/* chop the extension if present */
|
// copy the result into an string
|
||||||
if (strip_extension)
|
std::string result(start, end);
|
||||||
result = result.substr(0, result.find_last_of('.'));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user