Commit a7db159d authored by Martin Marinov's avatar Martin Marinov

Stop replacing digits after dots in set_filename_extension()

parent 06f91cdd
......@@ -7,6 +7,7 @@
#include <iomanip>
#include <fstream>
#include <limits>
#include <cctype>
namespace Base
{
......@@ -29,11 +30,17 @@ std::string make_filename(
std::string set_filename_extension(const char* _flnm, const char* _ext)
{
std::string flnm(_flnm);
const size_t dot_pos = flnm.find_last_of('.');
if (dot_pos != std::string::npos)
flnm.replace(flnm.begin() + dot_pos + 1, flnm.end(), _ext);
const auto dot_pos = flnm.find_last_of('.');
if (dot_pos == std::string::npos)
flnm += std::string(".") + _ext; // no dot, add the dot and the extension
else if (dot_pos + 1 == flnm.size())
flnm += _ext; // last char is dot, add the extension
else if (isdigit(flnm[dot_pos + 1])) // char after dot is a digit?
flnm += std::string(".") + _ext; // add the dot and the extension
else
flnm += std::string(".") + _ext;
flnm.replace(flnm.begin() + dot_pos + 1, flnm.end(), _ext);
return flnm;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment