1 // DefaultName.cpp
2
3 #include "StdAfx.h"
4
5 #include "DefaultName.h"
6
GetDefaultName3(const UString & fileName,const UString & extension,const UString & addSubExtension)7 static UString GetDefaultName3(const UString &fileName,
8 const UString &extension, const UString &addSubExtension)
9 {
10 int extLength = extension.Len();
11 int fileNameLength = fileName.Len();
12 if (fileNameLength > extLength + 1)
13 {
14 int dotPos = fileNameLength - (extLength + 1);
15 if (fileName[dotPos] == '.')
16 if (extension.IsEqualToNoCase(fileName.Ptr(dotPos + 1)))
17 return fileName.Left(dotPos) + addSubExtension;
18 }
19 int dotPos = fileName.ReverseFind(L'.');
20 if (dotPos > 0)
21 return fileName.Left(dotPos) + addSubExtension;
22
23 if (addSubExtension.IsEmpty())
24 return fileName + L"~";
25 else
26 return fileName + addSubExtension;
27 }
28
GetDefaultName2(const UString & fileName,const UString & extension,const UString & addSubExtension)29 UString GetDefaultName2(const UString &fileName,
30 const UString &extension, const UString &addSubExtension)
31 {
32 UString name = GetDefaultName3(fileName, extension, addSubExtension);
33 name.TrimRight();
34 return name;
35 }
36