cmObjectLocation.cxx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmObjectLocation.h"
  4. void cmObjectLocation::Update(std::string path)
  5. {
  6. this->Path = std::move(path);
  7. }
  8. std::string const& cmObjectLocation::GetPath() const
  9. {
  10. return this->Path;
  11. }
  12. cm::string_view cmObjectLocation::GetDirectory() const
  13. {
  14. auto const pos = this->Path.rfind('/');
  15. if (pos == std::string::npos) {
  16. return {};
  17. }
  18. return cm::string_view(this->Path.c_str(), pos);
  19. }
  20. cm::string_view cmObjectLocation::GetName() const
  21. {
  22. auto const pos = this->Path.rfind('/');
  23. if (pos == std::string::npos) {
  24. return this->Path;
  25. }
  26. auto const nameStart = pos + 1;
  27. return cm::string_view(this->Path.c_str() + nameStart,
  28. this->Path.size() - nameStart);
  29. }
  30. cmObjectLocation const& cmObjectLocations::GetLocation(UseShortPath use) const
  31. {
  32. if (use == UseShortPath::Yes && this->ShortLoc) {
  33. return *this->ShortLoc;
  34. }
  35. return this->LongLoc;
  36. }
  37. std::string const& cmObjectLocations::GetPath(UseShortPath use) const
  38. {
  39. return this->GetLocation(use).GetPath();
  40. }