-
Notifications
You must be signed in to change notification settings - Fork 401
/
file-explorer.cpp
54 lines (45 loc) · 1.53 KB
/
file-explorer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Copyright (c) 2016-2021 CNRS INRIA
//
#include <cstdlib>
#include "pinocchio/utils/file-explorer.hpp"
namespace pinocchio
{
void extractPathFromEnvVar(const std::string & env_var_name,
std::vector<std::string> & list_of_paths,
const std::string & delimiter)
{
const char * env_var_value = std::getenv(env_var_name.c_str());
if(env_var_value != NULL)
{
std::string policyStr(env_var_value);
// Add a separator at the end so that last path is also retrieved
policyStr += std::string(":");
size_t lastOffset = 0;
while(true)
{
size_t offset = policyStr.find_first_of(delimiter, lastOffset);
if (offset < policyStr.size())
list_of_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset));
if (offset == std::string::npos)
break;
else
lastOffset = offset + 1; // add one to skip the delimiter
}
}
}
std::vector<std::string> extractPathFromEnvVar(const std::string & env_var_name,
const std::string & delimiter)
{
std::vector<std::string> list_of_paths;
extractPathFromEnvVar(env_var_name,list_of_paths,delimiter);
return list_of_paths;
}
std::vector<std::string> rosPaths()
{
std::vector<std::string> list_of_paths;
extractPathFromEnvVar("ROS_PACKAGE_PATH",list_of_paths);
extractPathFromEnvVar("AMENT_PREFIX_PATH",list_of_paths);
return list_of_paths;
}
}