DefaultName.cpp 710 B

1234567891011121314151617181920212223242526
  1. // DefaultName.cpp
  2. #include "StdAfx.h"
  3. #include "DefaultName.h"
  4. static const wchar_t *kEmptyFileAlias = L"[Content]";
  5. UString GetDefaultName2(const UString &fileName,
  6. const UString &extension, const UString &addSubExtension)
  7. {
  8. int extLength = extension.Length();
  9. int fileNameLength = fileName.Length();
  10. if (fileNameLength > extLength + 1)
  11. {
  12. int dotPos = fileNameLength - (extLength + 1);
  13. if (fileName[dotPos] == '.')
  14. if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)
  15. return fileName.Left(dotPos) + addSubExtension;
  16. }
  17. int dotPos = fileName.ReverseFind(L'.');
  18. if (dotPos > 0)
  19. return fileName.Left(dotPos) + addSubExtension;
  20. return kEmptyFileAlias;
  21. }