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