From 79e8f8fb20f9c2a4aebd6178a99b40f4e7b4fccc Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 11 Apr 2015 17:42:32 +0200 Subject: cFile:ChangeFileExt now accepts extensions with leading dot, too. --- src/OSSupport/File.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/OSSupport/File.cpp') diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index fe72f34b4..43105b230 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -481,13 +481,25 @@ AString cFile::ChangeFileExt(const AString & a_FileName, const AString & a_NewEx ) { // No extension, just append the new one: - res.push_back('.'); + if (!a_NewExt.empty() && (a_NewExt[0] != '.')) + { + // a_NewExt doesn't start with a dot, insert one: + res.push_back('.'); + } res.append(a_NewExt); } else { // Replace existing extension: - res.erase(DotPos + 1, AString::npos); + if (!a_NewExt.empty() && (a_NewExt[0] != '.')) + { + // a_NewExt doesn't start with a dot, keep the current one: + res.erase(DotPos + 1, AString::npos); + } + else + { + res.erase(DotPos, AString::npos); + } res.append(a_NewExt); } return res; -- cgit v1.2.3