| #include "dbus_utility.hpp" |
| |
| #include <filesystem> // NOLINT |
| #include <string> |
| |
| #include "boost/system/error_code.hpp" // IWYU pragma: keep // NOLINT |
| |
| namespace dbus { |
| |
| namespace utility { |
| |
| bool getNthStringFromPath(const std::string& path, int index, |
| std::string& result) { |
| if (index < 0) { |
| return false; |
| } |
| |
| std::filesystem::path p1(path); |
| int count = -1; |
| for (auto const& element : p1) { // NOLINT |
| if (element.has_filename()) { |
| ++count; |
| if (count == index) { |
| result = element.stem().string(); |
| break; |
| } |
| } |
| } |
| return count >= index; |
| } |
| |
| } // namespace utility |
| } // namespace dbus |