FileSystemUtils.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/core/utils/FileSystemUtils.h>
  6. using namespace Aws::Utils;
  7. Aws::String PathUtils::GetFileNameFromPathWithoutExt(const Aws::String& path)
  8. {
  9. Aws::String fileName = Aws::Utils::PathUtils::GetFileNameFromPathWithExt(path);
  10. size_t endPos = fileName.find_last_of('.');
  11. if (endPos == std::string::npos)
  12. {
  13. return fileName;
  14. }
  15. if (endPos == 0) // fileName is "."
  16. {
  17. return {};
  18. }
  19. return fileName.substr(0, endPos);
  20. }
  21. Aws::String PathUtils::GetFileNameFromPathWithExt(const Aws::String& path)
  22. {
  23. if (path.size() == 0)
  24. {
  25. return path;
  26. }
  27. size_t startPos = path.find_last_of(Aws::FileSystem::PATH_DELIM);
  28. if (startPos == path.size() - 1)
  29. {
  30. return {};
  31. }
  32. if (startPos == std::string::npos)
  33. {
  34. startPos = 0;
  35. }
  36. else
  37. {
  38. startPos += 1;
  39. }
  40. size_t endPos = path.size() - 1;
  41. return path.substr(startPos, endPos - startPos + 1);
  42. }