1370b324cSopenharmony_ci// DefaultName.cpp 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#include "StdAfx.h" 4370b324cSopenharmony_ci 5370b324cSopenharmony_ci#include "DefaultName.h" 6370b324cSopenharmony_ci 7370b324cSopenharmony_cistatic UString GetDefaultName3(const UString &fileName, 8370b324cSopenharmony_ci const UString &extension, const UString &addSubExtension) 9370b324cSopenharmony_ci{ 10370b324cSopenharmony_ci const unsigned extLen = extension.Len(); 11370b324cSopenharmony_ci const unsigned fileNameLen = fileName.Len(); 12370b324cSopenharmony_ci 13370b324cSopenharmony_ci if (fileNameLen > extLen + 1) 14370b324cSopenharmony_ci { 15370b324cSopenharmony_ci const unsigned dotPos = fileNameLen - (extLen + 1); 16370b324cSopenharmony_ci if (fileName[dotPos] == '.') 17370b324cSopenharmony_ci if (extension.IsEqualTo_NoCase(fileName.Ptr(dotPos + 1))) 18370b324cSopenharmony_ci return fileName.Left(dotPos) + addSubExtension; 19370b324cSopenharmony_ci } 20370b324cSopenharmony_ci 21370b324cSopenharmony_ci int dotPos = fileName.ReverseFind_Dot(); 22370b324cSopenharmony_ci if (dotPos > 0) 23370b324cSopenharmony_ci return fileName.Left((unsigned)dotPos) + addSubExtension; 24370b324cSopenharmony_ci 25370b324cSopenharmony_ci if (addSubExtension.IsEmpty()) 26370b324cSopenharmony_ci return fileName + L'~'; 27370b324cSopenharmony_ci else 28370b324cSopenharmony_ci return fileName + addSubExtension; 29370b324cSopenharmony_ci} 30370b324cSopenharmony_ci 31370b324cSopenharmony_ciUString GetDefaultName2(const UString &fileName, 32370b324cSopenharmony_ci const UString &extension, const UString &addSubExtension) 33370b324cSopenharmony_ci{ 34370b324cSopenharmony_ci UString name = GetDefaultName3(fileName, extension, addSubExtension); 35370b324cSopenharmony_ci name.TrimRight(); 36370b324cSopenharmony_ci return name; 37370b324cSopenharmony_ci} 38