delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
filesystem.cpp
1
6
7
#include "delpi/util/filesystem.h"
8
9
#include <cstddef>
10
#include <filesystem>
11
#include <string>
12
#include <vector>
13
14
#include "delpi/util/logging.h"
15
16
namespace
delpi
{
17
18
std::string
GetExtension
(
const
std::string &name) {
19
const
std::size_t idx = name.rfind(
'.'
);
20
if
(idx == std::string::npos)
return
""
;
21
return
name.substr(idx + 1);
22
}
23
24
std::vector<std::string>
SplitStringByWhitespace
(
const
char
*in) {
25
std::vector<std::string> r;
26
for
(
const
char
*p = in; *p; ++p) {
27
while
(*p ==
' '
|| *p ==
'\t'
|| *p ==
'\r'
) ++p;
28
if
(*p ==
'\0'
)
break
;
29
int
length = 0;
30
while
(p[length] !=
' '
&& p[length] !=
'\t'
&& p[length] !=
'\r'
&& p[length]) ++length;
31
r.emplace_back(p, length);
32
p += length - 1;
33
}
34
return
r;
35
}
36
37
std::vector<std::string>
GetFiles
(
const
std::string &path,
const
std::string &extension) {
38
std::vector<std::string> files;
39
for
(
const
std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(path)) {
40
if
(!extension.empty() && entry.path().extension() != extension)
continue
;
41
files.emplace_back(entry.path());
42
}
43
return
files;
44
}
45
46
}
// namespace delpi
delpi
Global namespace for the delpi library.
delpi::GetFiles
std::vector< std::string > GetFiles(const std::string &path, const std::string &extension)
Get the files in a directory.
Definition
filesystem.cpp:37
delpi::GetExtension
std::string GetExtension(const std::string &name)
Get the extension of the file.
Definition
filesystem.cpp:18
delpi::SplitStringByWhitespace
std::vector< std::string > SplitStringByWhitespace(const char *in)
Split a C-string by whitespace.
Definition
filesystem.cpp:24
delpi
util
filesystem.cpp
Generated by
1.17.0