Wildmeshing Toolkit
split_path.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ranges>
3 #include <string_view>
4 #include <sstream>
5 
7 
8 inline auto split_path(const std::string_view& view)
9 {
10 #if defined(WMTK_ENABLED_CPP20)
11  using namespace std;
12  return std::ranges::views::split(view, "."sv) |
13  std::views::transform([](const auto& r) noexcept -> std::string_view {
14  return std::string_view(r.begin(), r.end());
15  });
16 
17 #else
18  std::vector<std::string> tokens;
19  if(view.empty()) {
20  tokens.emplace_back("");
21 
22  } else {
23  std::string v = std::string(view);
24  std::istringstream iss(v);
25  std::string token;
26  if(v.size() > 0 && v[0] == '.') {
27  tokens.emplace_back("");
28  }
29  while (std::getline(iss, token, '.')) {
30  if (!token.empty())
31  tokens.push_back(token);
32  }
33  }
34  return tokens;
35 #endif
36 }
37 } // namespace wmtk::components::multimesh::internal
Definition: autodiff.h:995
auto split_path(const std::string_view &view)
Definition: split_path.hpp:8