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